Due date on Request to auto populate based on the variable value.

rog
Giga Contributor

Hi all,

I have a requirement where the requested delivery date (due_date) should depend upon on a variable (end_dte)date value.

I have created a business rule on the catalog item and it is working, now I want the requested delivery date on the request to populate based on the same variable end_dte.

The business rule I have created is as follows:

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

  var gdt = current.variables.end_dte;

  current.due_date.setValue(gdt);

var gr=new GlideRecord('sc_request');

gr.addQuery('sys_id',current.request);

gr.query();

if(gr.next())

{

gr.due_date=current.variables.end_dte;

gr.update();

}

})(current, previous);

Thanks.

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Your code look fine to me. I have tested this on my end, it works for me. Make sure your business rule is a before insert one



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


  var gdt = current.variables.end_dte;


  current.due_date.setValue(gdt);


var gr=new GlideRecord('sc_request');


gr.addQuery('sys_id',current.request);


gr.query();


if(gr.next())


{


gr.due_date=current.variables.end_dte;


gr.update();


}


})(current, previous);


View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Roger,



What's your question?


Is your functionality working fine?



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,



The requirement is that the requested delivery date on 'requested item' and 'request' should be the same as the date selected on the form variable end_dte.



I have created a BR on requested item table, the RITM is populating the requested date value correctly but on the request it is not populating the value.



Thanks


Roger


Abhinay Erra
Giga Sage

Your code look fine to me. I have tested this on my end, it works for me. Make sure your business rule is a before insert one



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


  var gdt = current.variables.end_dte;


  current.due_date.setValue(gdt);


var gr=new GlideRecord('sc_request');


gr.addQuery('sys_id',current.request);


gr.query();


if(gr.next())


{


gr.due_date=current.variables.end_dte;


gr.update();


}


})(current, previous);