- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2016 03:16 AM
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 :
Please advise!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2016 05:31 AM
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());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2016 05:08 AM
Hi Michal,
I checked both my fields u_delivery_date and ADT_Effective_date have data type as "date" only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2016 05:31 AM
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());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2016 05:44 AM
Thank you that worked
Can you please tell me why daysAgo () din't work ? just asking out of curiosity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2024 04:26 AM
Your code needs a few adjustments to properly subtract two days from the ADT Effective Date. Use GlideDateTime to handle date operations. Instead of daysAgo(2), use addDaysUTC(-2) to subtract 2 days. Here's an updated version:
var del = current.request_item.variables.ADT_Effective_Date;
if (del) {
var gd = new GlideDateTime(del);
gd.addDaysUTC(-2); // Subtract 2 days
current.u_delivery_date = gd; // Set new delivery date
}
This code checks if the ADT date exists, subtracts two days, and assigns the new date to u_delivery_date. Ensure the field is of type GlideDateTime or date. I also face this issue on my 3 projects, Brand in Marketing, Brand Counters and Likely A Business.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2016 05:47 AM
Hi,
It works only Client side glide system is only client side(As per my Knowledge).