Set RITM State from update of SC_TASK

kshaw
Giga Guru

I am trying to write a business rule:

  • on Update
  • table: sc_task 

when service catalog task is updated BR runs.

Desired Outcome
When a task is updated by an agent, the business rule gets the value of service catalog variable ("comp_reviewStatus" - 3 options from pulldown) and sets the state on the RITM to either "Work in Progress" or "Awaiting Client.

script is:

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

	var status = current.variables.comp_reviewStatus;
	
    if (status == "under_review") {
		current.request_item.state = 2;  // Work in Progress
	}
	else if (status == "awaiting_client") {
		current.request_item.state = 5;  // Awaiting Client
	}
	else if (status == "completed") {
		current.request_item.state = 2;  // Work in Progress
	}

})(current, previous);

This is not working and RITM state is not being updated.

1 ACCEPTED SOLUTION

Saurabh Gupta
Kilo Patron
Kilo Patron

You should write your code onAfter BR as below.

 

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

	var status = current.request_item.variables.comp_reviewStatus;
	var tr=new GlideRecord('sc_req_item');
tr.addQuery('sys_id',current.request_item);
tr.query();
tr.next();
    if (status == "under_review") {
		tr.state = 2;  // Work in Progress
tr.update();
	}
	else if (status == "awaiting_client") {
		tr.state = 5;  // Awaiting Client
tr.update();
	}
	else if (status == "completed") {
		tr.state = 2;  // Work in Progress
tr.update();
	}

})(current, previous);

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

View solution in original post

3 REPLIES 3

Raj_Esh
Kilo Sage
Kilo Sage

Hi kshaw,

 

Just an input, if you are using flow designer, you can achieve this by leveraging Flow activities. Updating the RITM based on SCTASK state. Did you give it a try?

 

Thanks,

Raj

--Raj

Saurabh Gupta
Kilo Patron
Kilo Patron

You should write your code onAfter BR as below.

 

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

	var status = current.request_item.variables.comp_reviewStatus;
	var tr=new GlideRecord('sc_req_item');
tr.addQuery('sys_id',current.request_item);
tr.query();
tr.next();
    if (status == "under_review") {
		tr.state = 2;  // Work in Progress
tr.update();
	}
	else if (status == "awaiting_client") {
		tr.state = 5;  // Awaiting Client
tr.update();
	}
	else if (status == "completed") {
		tr.state = 2;  // Work in Progress
tr.update();
	}

})(current, previous);

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

Thank  you Saurabh, that worked fine.