Set Follow Up date from a date variable plus 5 days on RITM

Bidduam
Tera Guru

I have a variable called u_return_date, what I want to do is when someone submits their catalog item, the follow up field on the RITM is populated by getting the u_return_date value and adding 5 days to it.

eg: u_return_date is 01/07/2024 then make follow_up - 06/07/2024

 

What I have currently is a business rule on the sc_req_item table and is a before insert with the following script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
	var ReturnDate = g_form.getValue('current.u_return_date');
    ReturnDate.addDays(5);
    current.follow_up = ReturnDate;

})(current, previous);

 

 

2 ACCEPTED SOLUTIONS

Hi @Bidduam ,

 

You have used g_form which is client side API. Business rule is server side so it won't work.

 

Use the below it will work, I have tested in PDI.

 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var ReturnDate = new GlideDateTime(current.variables.u_return_date);
    ReturnDate.addDays(5);
    current.follow_up = ReturnDate;

})(current, previous);

 

 

Output:

SN_Learn_0-1719386488617.png

 

SN_Learn_1-1719386551101.png

 

 

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

I have tested it again:

 

SN_Learn_0-1719388198825.png

 RITM OOB field:

SN_Learn_1-1719388239741.png

 

 

 

Business Rule:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var ReturnDate = new GlideDateTime(current.variables.u_return_date);
    ReturnDate.addDays(5);
    current.follow_up = ReturnDate;

})(current, previous);

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

8 REPLIES 8

SN_Learn
Kilo Patron
Kilo Patron

Hi @Bidduam ,

 

As 'u_return_date' is a variable in the catalog item, you have to access it by the below:

current.variables.u_return_date;

 

Mark this as Helpful / Accept the Solution if this helps

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

No that doesn't make any difference unfortunately 

Hi @Bidduam ,

 

You have used g_form which is client side API. Business rule is server side so it won't work.

 

Use the below it will work, I have tested in PDI.

 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var ReturnDate = new GlideDateTime(current.variables.u_return_date);
    ReturnDate.addDays(5);
    current.follow_up = ReturnDate;

})(current, previous);

 

 

Output:

SN_Learn_0-1719386488617.png

 

SN_Learn_1-1719386551101.png

 

 

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

@SN_Learn 

Is the "start Date" you have a OOTB field? mine is a variable

Follow Up is an OOTB field

 

So in my scenario I am grabbing the value from a catalog item variable, trying to add 5 days to that date and putting the new value in an OOTB field on the RITM.

 

Is that the same as what you have done? Because it is definitely not working for me