- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 04:38 AM
Hello everyone
I want to add the number of months indicated in the field "nbmois" in order to obtain:
- in the field "quit date" = Field "Created" + Field "nbmois"
In the image below, we will have 12/04/2018 13:28:51
I create one "Business rule" but it doesn't work:
QuitDate();
function QuitDate()
{
var startDate = current.sys_created_on; // the name of field "Created" is "sys_created_on"
var n = current.u_nbmois; // the name of field "nbmois" is "u_nbmois"
current.u_quit_date = startDate.addMonthsUTC(n);// the name of field "Quit Date" is "u_nbmois"
return;
}
This may be due to a "variable type" problem?:
But I do not have the opportunity to put in the Type "Date/Time"
Thank you for you precious help
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 05:44 AM
QuitDate();
function QuitDate()
{
var n = current.u_nbmois; // the name of field "nbmois" is "u_nbmois"
var startDate = current.sys_created_on; // the name of field "Created" is "sys_created_on"
var endDate = new GlideDate();
endDate.setValue(startDate);
endDate.addMonthsUTC(n);
current.u_quit_date = endDate.getDate();// the name of field "Quit Date" is "u_nbmois"
//current.update() //this depends on business rule, uncomment if it is after business rule
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 04:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 05:15 AM
Hi Mustapha,
Please replace your script with the one i am attaching below.
This script worked on my instance.
Hope this works for you too..
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var startDate = current.sys_created_on;
var n = current.u_nbmois;
current.u_quit_date = startDate.getDisplayValue();
current.u_quit_date.getGlideObject().addMonthsUTC(n);
})(current, previous);
Thanks,
Ajinkya Pendhari
P.S. : Please mark this answer as helpful or correct if it meets your requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 05:44 AM
QuitDate();
function QuitDate()
{
var n = current.u_nbmois; // the name of field "nbmois" is "u_nbmois"
var startDate = current.sys_created_on; // the name of field "Created" is "sys_created_on"
var endDate = new GlideDate();
endDate.setValue(startDate);
endDate.addMonthsUTC(n);
current.u_quit_date = endDate.getDate();// the name of field "Quit Date" is "u_nbmois"
//current.update() //this depends on business rule, uncomment if it is after business rule
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 05:51 AM
Thank you so much
It works!