Date field using custom field renderer snippet has stopped working

  • 1
  • Problem
  • Updated 3 years ago
  • Solved
Date field using custom field renderer snippet has stopped working. It used to work fine before. Now it has stopped working and gives an error message saying required field value is not populated when trying to save the record.

Below is the snippet:
var field = arguments[0],
    value = arguments[1];
    
//set Contract expiry date to 365 days from today
var c=new Date();
c.setDate(c.getDate()+365);
var cYear=c.getFullYear();
var cMonth=c.getMonth()+1;
var cDay=c.getDate();

value = cYear+"-"+cMonth+"-"+cDay;

skuid.ui.fieldRenderers.DATE.edit( field, value );
Photo of Jayesh Bhatnagar

Jayesh Bhatnagar

  • 476 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Try setting a console log on the "Value" output.  Then compare that with model data for a date returned from salesforce. It looks like you are trying to parse your own salesforce date from the javascript date provided by your +365 calculation.  You should look into some of Skuid Time APIs that perform this parsing function more reliably.  http://help.skuidify.com/m/11720/l/129505-skuid-time 
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Jayesh I am surprised that this was ever "working", because the snippet above never actually updates the value of the Date field in the Skuid Model --- in the UI the value might have shown as the Date you were creating, but you need to use model.updateRow() (see the docs on the Model object) to actually change the value of the field in the Model.
Photo of Jayesh Bhatnagar

Jayesh Bhatnagar

  • 476 Points 250 badge 2x thumb
What I am trying to do is default today's date + 365 as the expiration date of a contract. But the user should be able to override it. So i built the above custom field render snippet. This defaults the date correctly.

But if I understand correctly I need to use an updateRow to actually save it on the model even before the user clicks the save button?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Yes that is correct, you need to use updateRow to save it to the Model.
Photo of Jayesh Bhatnagar

Jayesh Bhatnagar

  • 476 Points 250 badge 2x thumb
That resolved the problem. Thanks.