how to auto change status of change request form depends on catalog task status in servicenow

Arjun Reddy Yer
Mega Sage

Can anyone help me in getting this as need to auto change status of Change Request form depends on Catalog Task status in servicenow 

as off now when RITM is created then Catalog Task and Change Request are getting created via workflow.

@Ankur Bawiskar @Anil Lande @Sumalatha Y @BharathChintala @mattystern @priyasunku @asifnoor @Pradeep Sharma @SatyakiBose 

2 ACCEPTED SOLUTIONS

Sumalatha Y
Kilo Guru

Hi,

Configure flow as below to update change status.

SumalathaY_0-1678394535077.pngSumalathaY_1-1678394587125.pngSumalathaY_2-1678394620960.pngSumalathaY_3-1678394635496.pngSumalathaY_4-1678394656331.pngSumalathaY_5-1678394673479.png

Thanks & Mark Answer Correct/Hit Thumbs Up. If my inputs help you to achieve what you are looking.

Sumalatha Y

View solution in original post

@Arjun Reddy Yer 

you need to decide which state value to set here -2 or -1

try this updated script

(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 || -1'; //choice Value For Scheduled or Implement
gs.info('sample enter 1');
}
else if (current.state == '3')
{
gr.state = '3'; //Choice Value for Closed
gs.info('sample 2');
}else if(current.state == '4')
{
gr.state = '4'; //Choice value for Cancelled
gs.info('sample 3');
}else if(current.state == '1')
{
gr.state = '-5'; //Choice value for open
gs.info('sample 4');
}
gr.update();
}
})(current, previous);

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

View solution in original post

34 REPLIES 34

@Arjun Reddy Yer 

I already shared script above.

just use if else conditions in script to properly set CHG state based on sc task state

I hope that much scripting knowledge you must be having to complete the remaining part.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

the highlighted stages needs to get auto populate when the Catalog Task State changes  

 

Catalog Task                  Change Request

Open                        =    Open

Work in Progress    =   Scheduled, Implement

Closed Complete    =   Closed

Closed Incomplete  =  Canceled

 

yerasumalli_0-1678458095476.png

 

@Ankur Bawiskar @Anil Lande @Sumalatha Y @BharathChintala @mattystern @priyasunku @asifnoor @Pradeep Sharma @SatyakiBose 

written below mentioned script but it's not working

 

(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 (gr.state == current.state){
current.state = 'open';
gr.state = 'open';
} else if (current.parent.state == "change_request");
gr.update();
}

})(current, previous);

@Arjun Reddy Yer 

something like this. please enhance

(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 = 'choiceValueForScheduled or Implement';
		else if(current.state == '3')
			gr.state = 'Choice Value for Closed';
		else if(current.state == '4')
			gr.state = 'Choice value for Cancelled';
		else if(current.state == 'choiceValue for Open')
			gr.state = 'Choice value for open';
		gr.update();
	}

})(current, previous);
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

thanks a lot every thing is working fine but when the Catalog Task State changes to Closed Complete then the Change Request State is changing to Cancelled.

 

@Ankur Bawiskar @Anil Lande @Sumalatha Y @BharathChintala @mattystern @priyasunku @asifnoor @Pradeep Sharma @SatyakiBose 

Task Table Values of State Field

yerasumalli_0-1678463738339.png

Change Request Table Values of State Field

yerasumalli_1-1678463808464.png

Business Rule which had written

 

(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 or -1'; //choice Value For Scheduled or Implement
else if(current.state == '3')
gr.state = '3'; //Choice Value for Closed
else if(current.state == '4')
gr.state = '4'; //Choice value for Cancelled
else if(current.state == '1')
gr.state = '-5'; //Choice value for open
gr.update();
}

})(current, previous);

@Arjun Reddy Yer 

please debug by adding gs.info() statements.

I believe I have answered your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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