javascript error on createRow

Hi Team!

I’m running the snippet below from a model action (when the Status__c field is updated on the model), to create a new row:

//Run this when Status is updated on model.<br>var $ = skuid.$,<br>&nbsp; &nbsp; arg = arguments[0],<br>&nbsp; &nbsp; m = arg.model,<br>&nbsp; &nbsp; r = arg.row;<br>console.log(m,r);<br>console.log(r.Status__c);<br>if (r.Status__c == 'No show'){<br>&nbsp; &nbsp; m.createRow({<br>&nbsp; &nbsp; &nbsp; &nbsp; additionalConditions:[<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Patient_Case__c: r.Patient_Case__c},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Interaction_Category__c: 'Scheduling'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Interaction_Purporse__c: 'No show follow-up'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Interaction_Type__c: 'Call'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Status__c: 'Scheduled'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Date__c: skuid.time.getSFDateTime( new Date() )}<br>&nbsp; &nbsp; &nbsp; &nbsp; ]<br>&nbsp; &nbsp; });<br>&nbsp; &nbsp; m.save();<br>}


I’m getting this javascript error:



Here’s skuid_SkuidJS:formatted around line 3136:


Any thoughts on this one?

That code looks fine.  Are you sure it’s not somewhere else that is causing the error?  Probably in one of your custom field renderers.  The stack trace shows createRow running just fine.  It looks like a field renderer is being triggered as a result of your createRow and the issue is in there.

I eliminated the custom renderers. That was the problem.

However, when the createRow runs, I’m getting the error; Required fields missing: [Patient Case, Date] even though I’ve defined those fields in the script.

The console log shows that they exist.

Here’s the row that’s being created:


It looks like it’s only getting fields from the conditions defined on the model, not from the values I’m passing through additionalConditions.

What am I missing?

Try this…


additionalConditions:[&nbsp; &nbsp; <br>&nbsp; &nbsp; {field : 'Patient_Case__c', value : r.Patient_Case__c},<br>&nbsp; &nbsp; {field : 'Interaction_Category__c', value : 'Scheduling'},<br>&nbsp; &nbsp; {field : 'Interaction_Purporse__c', value : 'No show follow-up'},<br>&nbsp; &nbsp; {field : 'Interaction_Type__c', value : 'Call'},<br>&nbsp; &nbsp; {field : 'Status__c', value : 'Scheduled'},<br>&nbsp; &nbsp; {field : 'Date__c', value : skuid.time.getSFDateTime( new Date() )}<br>]

Worked! Thanks, Ben.

Do we always need to write additionalConditions that way? Is there an explanation for when to use
{MyField__c: ‘DefaultValue’} vs. {field: ‘MyField__c’, value: ‘DefaultValue’}?

Thanks!

Yes, additional conditions need to be actual skuid.model.Condition objects. You can see the api docs for this object here. The api docs let you know what type of javascript objects are needed for each api. Some of the inconsistencies you see have good reasons, and others just come from the fact that Skuid has evolved over time, but the APIs must remain constant.  

I’m guessing the difference you’re mentioning is the difference between how skuid.model.Model.updateRow() and skuid.model.Model.createRow() work.  The API docs here outline what inputs you need for the various API methods.

Thanks, Ben! Yep, I was confusing the syntax for updateRow() and createRow().