daysAgo ()

sunny13
Giga Expert

Hi All,

I have a field in catalog form call ADT effective date which will be filled out by user.

For specific items i want the tasks to have delivery date as two days ago of ADT effective date.

I'm using a After BR on task form   because i want this script to run for 5 items which i have specified in the condition.

My Code :

function onAfter(current, previous) {

  //This function will be automatically called when this rule is processed.

  var del=current.request_item.variables.ADT_Effective_Date.getDisplayValue();

  gs.addInfoMessage('the adt date is '+del);

  /*var gd = new GlideDateTime(del);

  gs.addInfoMessage('the adt date is '+gd);*/

  var agotwoDays =del.daysAgo(2);

  gs.addInfoMessage('removed 2 Days '+agotwoDays);

  /*var add= addtwoDays.getDate();

  gs.addInfoMessage('added 2 Days '+addtwoDays);*/

  //current.u_delivery_date=addtwoDays.getDisplayValue();

  current.u_delivery_date=agotwoDays;

// current.update();

}

----------------------------------------------------------------------------------------------

Error Message :

find_real_file.png

Please advise!!!

1 ACCEPTED SOLUTION

Midhun1
Giga Guru

Hi,



Use this code it will work:



Pass the date to Glide date time and code follows:




var gdt = new GlideDateTime(agotwoDays);


gdt.addDays(-2);


gdt.getLocalDate();


gs.addInfoMessage("date2"+gdt.getLocalDate());


View solution in original post

11 REPLIES 11

Midhun1
Giga Guru

Hi Sajin,



Use     var agotwoDays =gs.daysAgo(2); instead     var agotwoDays =del.daysAgo(2);


Hi MIdhun,



Just to be clear gs. will get the current date and time rite?


i want to compare the ADT effective date and then set the delivery date to two days before.



Any ways let me try


Hi Midhun,



Yes gs. takes current time .



Please see my info mesage,



find_real_file.png



I'm supposed to get the removed 2 days as 2016 -06-02


michal29
Mega Guru

Hello Sajin,



Check the data types for var del=current.request_item.variables.ADT_Effective_Date.getDisplayValue();


and data type accepted by daysAgo(2);



It may be that you want to get daysAgo of a string, or other data -format that can't return anything from this function



Regards,


Michal