Planned start date and end date is not getting populated to the change task when change is created

Gayathree Seeth
Tera Expert

Hi,

Could you please help me with this case!!

1. When i create the change request, planned start and end date from the change request is not getting populated into the change task. (But when i update the change with new start and end date it is working)

2. Below is my code from Before Business rule(Insert and update) .

 

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

// Add your code here
var gr = new GlideRecord('change_task');
gr.initialize();
gr.addQuery('change_request',current.sys_id);
gr.query();
if(gr.next())
{
gr.planned_start_date = current.start_date;
gr.planned_end_date = current.end_date;
gr.update();
}
})(current, previous);

 

GayathreeSeeth_0-1680258836257.png

 

 

 

1 ACCEPTED SOLUTION

Gayathree Seeth
Tera Expert

Hi Kamil and Manju thanks for the help!!

 

I have created the below BR (Before,insert) which helped to populate the start date and end date from the change request to change task.

 

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

// Add your code here
current.planned_start_date=current.change_request.start_date +' ';
current.planned_end_date=current.change_request.end_date +' ';


})(current, previous);

View solution in original post

13 REPLIES 13

manjusha_
Kilo Sage

Change your business rule from before to after (insert and update).

 

Normally we should use before business rule to update current record only (here change record).

To create/update related record (Here related record is change task)we should use after business rule as a ServiceNow best practice .

 

Use below link for your reference-

https://www.servicenow.com/community/developer-forum/updating-records-with-after-business-rules/m-p/...

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

 

Hi,

Thanks for the Reply.

 

Even though we tried using After BR (insert and update) we get the same thing which was not expected.

Can you help us with the code we mentioned.

 

Thanks!!

 

@Gayathree Seeth 

Update your code as below-

Check whether info message showing on form or not 

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

// Add your code here
var gr = new GlideRecord('change_task');
gr.addQuery('change_request',current.sys_id);
gr.query();
if(gr.next())
{

gs.addInfoMessage("Checking after business rule for change tasks");
gr.planned_start_date = current.start_date;
gr.planned_end_date = current.end_date;
gr.update();
}
})(current, previous);

 

Thanks,

Manjusha Bangale

Kamil Smusz
Kilo Sage

Hi @Gayathree Seeth ,

 

Please remove gr.initialize(); from your code. This is used when you want to create new record in table. No needed here.