javascript error on createRow

  • 1
  • Problem
  • Updated 4 years ago
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.
var $ = skuid.$,
    arg = arguments[0],
    m = arg.model,
    r = arg.row;
console.log(m,r);
console.log(r.Status__c);
if (r.Status__c == 'No show'){
    m.createRow({
        additionalConditions:[
            {Patient_Case__c: r.Patient_Case__c},
            {Interaction_Category__c: 'Scheduling'},
            {Interaction_Purporse__c: 'No show follow-up'},
            {Interaction_Type__c: 'Call'},
            {Status__c: 'Scheduled'},
            {Date__c: skuid.time.getSFDateTime( new Date() )}
        ]
    });
    m.save();
}

I'm getting this javascript error:



Here's skuid_SkuidJS:formatted around line 3136:


Any thoughts on this one?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,470 Points 10k badge 2x thumb
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.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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?
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,470 Points 10k badge 2x thumb
Try this...


additionalConditions:[    
    {field : 'Patient_Case__c', value : r.Patient_Case__c},
    {field : 'Interaction_Category__c', value : 'Scheduling'},
    {field : 'Interaction_Purporse__c', value : 'No show follow-up'},
    {field : 'Interaction_Type__c', value : 'Call'},
    {field : 'Status__c', value : 'Scheduled'},
    {field : 'Date__c', value : skuid.time.getSFDateTime( new Date() )}
]
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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!
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,470 Points 10k badge 2x thumb
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.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Ben! Yep, I was confusing the syntax for updateRow() and createRow().