Javascript for adding days to a date field on Skuid Platform?

  • 1
  • Question
  • Updated 11 months ago
  • Answered
Hi all,

I have struggled with this for a while but it is now urgent. My javascript is not anywhere near good.

I have a 

Model - called Dates
Field 1 : {{Date}}
Field 2 : {{Days}}
Field 3 : {{NewDate}}

I would like to get a snippet that runs to add Days to Date and insert NewDate

I tried this.. but wrong :(


var params = arguments[0],   $ = skuid.$;
var model = skuid.$M('Dates');
var row = model.getFirstRow();
var dateVar = row.Date;
var daystoadd = row.Days;

dateVar.setDate(dateVar.getDate() + daystoadd);

model.updateRow(row,{NewDate : dateVar});



Can anyone see where I have screwed up )




 
Photo of David Forder

David Forder

  • 2,144 Points 2k badge 2x thumb

Posted 11 months ago

  • 1
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
Yo!

A couple of things here - I think you need to create a javascript date object - so change your dateVar declaration to this:

var dateVar = new Date(row.Date);

Then you can do stuff to it. I sometimes use the moment.js library for date manipulation.

Also, make sure you're not meaning to reference custom fields that would instead need a '__c' after the field name.
(Edited)
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
Ooops - just saw that you're using Skuid Platform so the custom field thing I mentioned does not apply.
Photo of David Forder

David Forder

  • 2,144 Points 2k badge 2x thumb
Thanks Luois.. adding the dateVar declaration worked!

Appreciate the assist ))