The CreatorCon Call for Content is officially open! Get started here.

Business rule not setting sc_req_item stage value

Sam Ogden
Tera Guru

Hi All,

I am in the middle of creating a new workflow for a catalog item.

I have a business rule running on change of a field on the catalog task.  The filed on the catalog task is 'u_job_category'.

When the value of this is 'Rescope requested' the following rule runs:

After update business rule to run when cat item is BAU Change Request V2 and job category changes to 'rescope requested.

(function executeRule(current, previous /*null when async*/) {
    var item = current.request_item;
	//gs.log("reqItem - " + item);
	var gr = new GlideRecord("sc_req_item");
	gr.addQuery('sys_id', current.request_item);
	gr.query();
	if(gr.next()) {
		gr.state = 2;
		gr.comments = 'test comment';
		gr.stage = 'rescope';
		gr.u_rescope_requested = 'true';
		gr.update();
	}

})(current, previous);

The state, comments, and u_rescope_requested fields all work, but I was trying to also set the 'stage' value, but this is not working - due to this I know that the business rule is firing.

I've already added the stage (label = Rescope Requested, value = rescope') to the workflow properties.

I have 2 other business rules that run when job category change to other values and these are setting the stage correctly.  I have copied the script from these and pasted it for this business rule and just amended the value to be set, but it still does not set the value.

Any suggestions?

Thanks

Sam

12 REPLIES 12

Sorry - Wrong answer. This business rule is NOT modifying the current object, so BEFORE is not the right answer. It is clearly modifying a related record - which should happen in an AFTER rule.

Thank you Chuck Tomasi for your concern.

Hi Chuck,

Thanks for this.

I've just been trying to work this out further.

When I click my UI action on the sc_task form it sets 'u_job_category' to the value 'rescope'.

The business rule then fires, and the RITM state change from pending to work in progress, but the stage field does not update.  In the related list for tasks, if I then change the job category to something else and then change it back to 'rescope' the stage value does change.

My business rule is as follows:

find_real_file.png

 

Have you turned on Debug business rules to ensure the BR is firing when it is supposed to?

Have you used the script debugger to step through the code in the BR to ensure it is working as expected?

Have you checked the logs (System Logs> System Log> All) to see if there are any signs of trouble?

Hi Chuck,

Thanks for the above.  I've not used the debug tool before, is there any tutorials on this?

I know that the rule is firing when I am expecting it to as it is updating the state value.  I've also added the following line after the stage update:

gr.comments = 'test comment';

 

and this also gets added to the log.  It is just the update to the 'stage' field that does not happen?

thanks

Sam