How add / edit / remove many to many relationships in google app maker using tables? - many-to-many

I have the following scenario centered around the relationship between 2 models: Assets and Activities.
Many Assets can be INPUT of Many Activities at parallel times.
Having that in mind - I want to create UI, which allows me to:
from the perspective of Activity:
add Assets as related to the Activity into a table by selecting them from an existing table of Assets showing all created Assets.
Be able to remove the relationship by clicking a button (which would not delete the whole record in the table).
Please help. Thank you in advance!
I tried binding custom code to an onClick event to a button, which is on the same row as the Asset record I would like to un-relate from an associated activity:
var index = widget.root.datasource.item.Assets.indexOf(widget.datasource.item);
widget.root.datasource.item.Assets.splice(index, 1);
This returns:
Cannot read property 'indexOf' of undefined
at Strategy_TableView.Panel1.Table2.Table2Body.Table2Row.Button5.onClick:1:51
I also have yet to try to find a way to add existing Assets to the related to Activities table.

Suggested code edits to get this working correctly would be:
var datasourcerelation = widget.root.datasource.relations.Services;
var index = datasourcerelation.items.indexOf(widget.datasource.item);
datasourcerelation.items.splice(index, 1);
For whatever reason referencing datasource.item.Services in relation to JS array functions does not give you the result needed. I am not sure why this is, but you have to use datasource.relations.Services instead.
In regards to adding to the relation use:
var datasourcerelation = widget.root.datasource.item.Services;
datasourcerelation.push(widget.datasource.item);
Note that in the case of adding a relation datasource.item.Services works fine. I am not sure why this is different.

Related

In testrail API how do I get project_id from case data?

I am trying to add a run with the add_run endpoint, but in my automation code I only have the test cases ids but not the project id (which according the the docs is mandatory).
Right now I am doing:
get all projects with /get_projects
get all cases /get_cases/{project_id}
Then I loop over the cases I get and add the project_id to the case so I could create an add_run with the proper project_id.
This seems like the wrong way to do it.
Anybody has a better solution?
Also is there a way to create a run without a project_id? for example if I have a sanity run that includes cases from many projects.
Any help is appreciated.
You can do the following to get the parent project ID:
get the case by ID and capture value of the suite_id field
get the parent suite by the value of the suite_id field and capture value of the project_id field <--- here you have your project ID and can use it for creating runs.

Laravel Eloquent - auto-numbering on has many relationship

I'm very much a beginner when it comes to database relationships hence what I suspect is a basic question! I have two database tables as follows:
Projects
id
company_id
name
etc...
rfis
id
project_id (foreign key is id on the Projects table above)
Number (this is the column I need help with - more below)
question
The relationships at the Model level for these tables are as follows:
Project
public function rfi()
{
return $this->hasMany('App\Rfi');
}
RFI
public function project()
{
return $this->belongsTo('App\Project');
}
What I'm trying to achieve
In the RFI table I need a system generated number or essentially a count of RFI's. Where I'm finding the difficulty is that I need the RFI number/count to start again for each project. To clarify, please see the RFI table below which I have manually created with the the 'number' how I would like it displayed (notice it resets for each new project and the count starts from there).
Any assistance would be much appreciated!
Todd
So the number field depends on the number of project_id in the RFI table. It is exactly the number of rows with project_id plus one.
So when you want to insert a new row, you calculate number based on project_id and assign it.
RFI::create([
'project_id' => $project_id,
'number' => RFI::where('project_id', $project_id)->count() + 1,
...
]);
What I understood is that you want to set the value of the "number" field to "1" if it's a new project and "increment" if it's an existing project. And you want to automate this without checking for it every time you save a new row for "RFI" table.
What you need is a mutator. It's basically a method that you will write inside the desired Model class and there you will write your own logic for saving data. Laravel will run that function automatically every time you save something. Here you will learn more about mutators.
Use this method inside the "RFI" model class.
public function setNumberAttribute($value)
{
if(this is new project)
$this->attributes['number'] = 1;
else
$this->attributes['number']++;
}
Bonus topic: while talking about mutators, there's also another type of method called accessor. It does the same thing as mutators do, but just the opposite. Mutators get called while saving data, accessors get called while fetching data.

How can I clear a specific filter without clearing all filters?

Background:
I am creating an app that stores record of trainings that employees in a company took in table. I want to filter the rows of the table based on training name and/or employee name. I was able to figure out this first part, and I was able to create a button that clears all the filters and reloads the entire table using the clearFilters() function.
Problem:
I want to create two buttons that clear the filter selections one ("All Trainings") for the training name and one ("All Employees") for the employee name. To be more clear, when I click on the "All Trainings" button, I want to clear the filters on the training name, but not on the Employee name. This will become useful once I have a table with multiple fields that I want to filter, and I want to navigate the table without having to reset all fields every time.
I tried searching the functions available on Google App Maker, but there was nothing that seemed to be able to solve my problem. Any suggestions?
From the Reference about datasources:
https://developers.google.com/appmaker/models/datasources#query_datasources
Like field filters, assigning null to a relation filter property clears that restriction.
So, something like:
datasource.query.filters.Employee._contains = null;
datasource.load();
should work for you.
I am sure there is a better way to do this, so you may want to wait for someone smarter to chime in, but I BELIEVE you can just have your button clear the filters, but reapply a new filter.
So for my situation I have the table do a filter for items that are listed as "Complete", so those are hidden when the user opens the page.
Then, when the users filter another field and want to clear out that search I didn't want the "Complete" items to reappear (which is what happened when I just used the clearFilters() function. So my workaround was to make the clear button actually clear the filter, but apply the original "Complete" filter.
So for my OnClick action, for my "Clear Button" I have:
widget.datasource.query.clearFilters();
widget.datasource.load();
app.closeDialog();
var datasource = app.datasources.TestModel;
datasource.query.filters.Status._notContains = 'Complete';
datasource.load();
The
widget.datasource.load();
app.closeDialog();
May be redundant/unnecessary.
Can you simply take 3 steps in your onClick handler?
(1) clear all filter
(2) set the employee name filter
(3) load data

Updating a single row in TaffyDB

I currently have a database setup within an html page and my requirement is to update a single row within the application.
I could refresh the database with "fresh" data, but that would require too much time.
I had a look at
dbSports().update("aName", object.aname);
However it seems to update all the records in my database instead of just one. Are there any answers to this particular issue?
The Documentation on the matter is missing a major chunk of information, but is covered in a presentation done by the author of the library (http://www.slideshare.net/typicaljoe/better-data-management-using-taffydb-1357773) [Slide 30]
The querying object needs to be pointing to the object you want to update and editing happening from there. i.e.
var obj = dbObject({
Id : value.id
}).update(function() {
this.aName = object.aname;
return this;
});
Where the object in the query points to the ID of the row and the update function then points to it aswell and the callback updates the value that the application needs to update
you first have to find the matching record, then update it
yourDB({"ID":recordID}).update({
"col1":val1,
"col2":val2,
"col3":val3
});

Can I insert deserialized JSON SObjects from another Salesforce org into my org?

We have the need to clone a complex data structure from one org to another. This contains a series of custom SObjects, including parents and children.
The flow would be the following. On origin org, we just JSON.serialize the list of SObjects we want to send. Then, on target org, we can JSON.deserialize that list of objects. So far so good.
The problem is that we cannot insert those SObjects directly, since they contain the origin org's IDs and Salesforce won't let us insert objects that already have Ids.
The solution we found is to manually insert the object hierarchy, maintaining a map of originId > targetId and fixing the relationships manually. However, we wonder if Salesforce provides an easier way to do such a thing, or someone knows a better way to do it.
Is there an embedded way in Salesforce to do this? Or are we stuck into a tedious manual process?
List.deepClone() call with preserveIds = false might deal with one problem, then:
Consider using upsert operation to build the relationships for you.
Upsert not only can prevent duplicates but also maintain hierarchies.
You'll need an external Id field on the parent, not on the children though.
/* Prerequisites to run this example succesfully:
- having a field Account_Number__c that will be marked as ext. id (you can't mark the standard one sadly)
- having an account in the DB with such value (but the point of the example is to NOT query for it's Id)
*/
Account parent = new Account(Account_Number__c = 'A364325');
Contact c = new Contact(LastName = 'Test', Account = parent);
upsert c;
System.debug(c);
System.debug([SELECT AccountId, Account.Account_Number__c FROM Contact WHERE Id = :c.Id]);
If you're not sure whether it will work for you - play with Data Loader's upsert function, might help to understand.
If you have more than 2 level hierarchy on the same sObject type I think you'd still have to upsert them in correct order though (or use Database.upsert version and keep on rerunning it for failed ones).