Snippet to conditionally set a default value for a DateTime field

So I’m making a wizard to delegate a case to a different user (using a custom ‘delegated to’ field, instead of changing owner)

I also have a Due_Date__c field.

In the wizard, I’d like to set the Due_Date__c field to ‘Today’ if there’s no value.

I’m using the Action Framework on the ‘next step’ button on step1 of the wizard.
- I can use an action to set the Due_Date__c field to Today, but that unconditionally overwrites the existing date if is already set.

So I made the below inline snippet, based on one I found to another question, as an Action step, followed by a navigate to step2 action.

Console output shows it’s updating the field, but when step2 loads, the Due_Date__c field is still blank.

I tried adding a save-model action, and that works, but I’d like to have the wizard ‘cancelable’.
(What’s the correct way to post code?)


var params = arguments[0], step = params.step, $ = skuid.$; var caseDataModel = skuid.model.getModel('CaseData'); var thisCaseData = caseDataModel.getFirstRow(); var dueDate = thisCaseData.Due_Date__c; if (!dueDate) { console.log('!dueDate'); dueDate = Date(); console.log(dueDate); caseDataModel.updateRow(thisCaseData,'DueDate__c',dueDate); // $.each(caseDataModel.registeredItems,function(){ // this.refreshFields(); // }); } var testCaseData = caseDataModel.getFirstRow(); var newDueDate = testCaseData.Due_Date__c; console.log('Test dueDate=' + dueDate); 

Ok, so I’ve got lot’s of bugs.  Still much to learn about JS and Skuid

Key tips for any lurkers:
- Spell field names correctly.  model.updateRow doesn’t give you a console error if you have the field name spelled wrong, ie. DueDate__c instead of the correct Due_Date__c

  1. Spelling Matters!! Spell field names correctly.  model.updateRow doesn’t give you a console error if you have the field name spelled wrong, ie. DueDate__c instead of the correct Due_Date__c
  2. RTFM Skuid datetime fields from models are Salesforce datetime fields which are text, not JS date variables.
  3. RTFM Use model.updateData() to update data in the model so it goes back to the screen. 

So many things right here. 

You found the right way to post code. 
You are looking in your console for errors. 
You found that SF dates are not JS dates.  Look at the Skuid Time Utils for a way of translating back and forth. 

Keep working on the snippet.  You are making headway. 

If I have time tomorrow I’ll try to write it up for you.