Field set in JavaScript snippet are blank

  • 1
  • Problem
  • Updated 3 years ago
I have the following JavaScript snippet that create a row in a related model, based on the selected tables Ids. The snippet creates the correct number of rows, but does not pass values to the specified rows. The console is not showing any errors.

var params =arguments[0];
var $ = skuid.$;
var models = skuid.model.map();

var Ids = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){
return item.row.Id;
});

var newSummaryClient = models.NewSummaryClient;
var summariesPU = models.SummariesPU;

$.each(Ids,function(){
var currentId = this;
var row = newSummaryClient.createRow({
additionalConditions: [
{ field: 'Vendor_Relationship__c', value: currentId, operator: '=', nameFieldValue: currentId.Name },
{ field: 'Summary__c', value: summariesPU.Id, operator: '=', nameFieldValue: this.Name }
]
});
});
Photo of Brayden Smith

Brayden Smith

  • 1,078 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Brayden,

What are the values in the newSummaryClient rows when you look at them in the console? Is it possible that the models are updated but the ui is not? Occasionally I have to forcibly re-render components after updating with javascript.
Photo of Brayden Smith

Brayden Smith

  • 1,078 Points 1k badge 2x thumb
Hey Matt--

I'm not sure exactly how to view that, here's what I've done in my code. I've added a console log after the Id's are assigned, at the beginning of the loop to check the currentId value, and after the row is assigned.

I'm not sure how to interpret what I see.

var params =arguments[0];
var $ = skuid.$;
var models = skuid.model.map();

var Ids = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){
return item.row.Id;
});

console.log(Ids);

var newSummaryClient = models.NewSummaryClient;
var summariesPU = models.SummariesPU;

$.each(Ids,function(){
var currentId = this;
console.log(currentId);
var row = newSummaryClient.createRow({
additionalConditions: [
{ field: 'Vendor_Relationship__c', value: currentId, operator: '=' },
{ field: 'Summary__c', value: summariesPU.Id, operator: '=' }
]
});
console.log(row);
});
The attached image is after I've selected 2 rows.

Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
after you run your code, just type this into the console and see what you get:

skuid.$M('NewSummaryClient').getRows();
You can use the > arrows to expand the row objects that the console will return to see what the values are.
(Edited)
Photo of Brayden Smith

Brayden Smith

  • 1,078 Points 1k badge 2x thumb
It looks like the Vendor_Relationship__c value is being set. But it doesn't look like the Summary__c value is being set.

The summariesPU model only has one record returned. Instead of referencing the model, do I need to specifically reference the first row of that model?

Also, how to a rerender the table that shows the NewSummaryClient model?

Thanks for all your help on this.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Brayden,

sorry I didn't look deeper into your code. You're right about the reference to the first row. summariesPU.Id is just the name of the model. Replace that with 
summariesPU.getFirstRow().Id
and you should be good to go.