how to populate assigned to field in change request based on SCTASK assigned to field

Arjun Reddy Yer
Tera Guru

Can anyone help me in getting this as I need to auto populate Assigned to field in Change Request based on SCTASK Assigned to Field. In Change request Assignment Group is getting populated via workflow but Assigned to field should get populate based on SCTASK Assigned to field selection. @Ankur Bawiskar @Vasantharajan N 

 

 

SCTASK Assigned to:

ArjunReddyYer_0-1681089356037.png

 

Change Request Assigned to:

ArjunReddyYer_1-1681089440428.png

 

1 ACCEPTED SOLUTION

@Arjun Reddy Yer - Please use the below code in your BR on sc_task table and check. 

 

var ritm_sysId = current.request_item.toString();

var chGr = new GlideRecord('change_request');
chGr.addQuery('parent', ritm_sysId); // As you are setting Parent field on change request to RITM sys_id, As per the create task script you shared.
chGr.addActiveQuery(); // only use active change ticket. Please apply filters if rquired on state.
chGr.query();
if (chGr.next()) {
    chGr.assigned_to = current.assigned_to.toString(); // Update the curret SC_TASK assigned to Change Assigned to
    chGr.update();
}

 


Thanks & Regards,
Vasanth

View solution in original post

5 REPLIES 5

Anil Lande
Kilo Patron

Hi,

You can use after BR on SC task (or flow) which should run after task is updated and assignd_to changes.

Business rule would be like below:

AnilLande_0-1681091853976.png

 

AnilLande_1-1681091873028.png

 

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

	var chGr = new GlideRecord('change_request');
	chGr.addQuery('sys_id',current.request_item.u_related_change);  // use field as per your configuration which stores related change ID
	chGr.query();
	if(chGr.next()){
		chGr.assigned_to = current.assigned_to.toString();
		chGr.update();
	}
	

})(current, previous);
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

u_related_change

Can I know which field it's referring to like Change Request Name or any another

Vasantharajan N
Giga Sage
Giga Sage

@Arjun Reddy Yer - How you are relating SCTASK with CHANGE request?


Thanks & Regards,
Vasanth

By using workflow 

Designed Workflow:

 

ArjunReddyYer_0-1681108136814.png

 

Script Used in Create Task: 

var sgdt = new GlideDateTime(current.approval_set);
task.start_date = sgdt;
var days=11;
//assuming there are 8 business hours or use 24 if you want to use complete day in calculation
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); //put sys_id of your schedule for weekdays here
var end = schedule.add(sgdt , dur);
task.end_date = end ;


task.short_description = current.number + ' ' + 'Standard change Request for Firewall Change Request'; //auto populating short description field with RITM number on Change Request
task.u_impacted_bu = current.variables.company; //auto populating Impacted BU on Change Request
task.justification = current.number + ' ' + 'Refer to Firewall Rule Service Request'; //auto populating RITM number on Change Request
task.parent = current.sys_id;
task.created_from = 'workflow';
task.priority = current.variables.priority;

task.u_loc_reg_cab = current.variables.testtest;

 Business Rule Used in auto changing Change Request State to Schedule:

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

var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.request_item);
gr.query();
if (gr.next()) {

if (current.state == 2)

{
gr.state = -2; //choice Value For Scheduled

}
gr.setWorkFlow(false);
gr.update();

}
})(current, previous);

https://www.servicenow.com/community/developer-forum/required-to-auto-change-state-of-change-request...