Business rule that writes a variable form one ticket into the message of another ticket

Dan Lewis
Giga Contributor

Hello,

The scenario is this;

I have a catalog item in our Service Portal called Request Help.  In this Request Help catalog item we ask for a reference ticket number.  This reference ticket number would be an existing ticket in our ServiceNow instance.  When a new Request Help catalog item is submitted I want to write this new ticket number into the reference ticket work notes.

 

I am able to do this in a Flow, but there is already a Flow attached to this catalog item.

So I think I need to do this with a business rule and a custom script, but my business rule script skills are minimal at best.  Can anyone give me some tips, resources, or examples that might help.

Thank you,
Dan

12 REPLIES 12

Dan H
Tera Guru

Hi,

I am assuming you want to copy the RITM number of the new request help item into the related incident's worknote field.

 

Business rule:

find_real_file.png

 

find_real_file.png

 

Script:

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

	var incident = current.variables.ticket; //replace 'ticket' with name of your ticket reference field
	var incidentGr = new GlideRecord('incident');
	incidentGr.get(incident);
	if(incidentGr){
		incidentGr.work_notes= ''+current.number;
		incidentGr.update();
	}
})(current, previous);

 

Hope this helps.

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

 

Dan Lewis
Giga Contributor

Hi,

This worked great for an incident.

I know I wasn't specific, but I am trying to do this for a existing requested item.

Any idea how I would do that?

Thank you,

Dan

Sure,

Should be:

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

	var ritm = current.variables.ticket; //replace 'ticket' with name of your ticket reference field
	var ritmGr = new GlideRecord('sc_req_item');
	ritmGr.get(ritm);
	if(ritmGr){
		ritmGr.work_notes= ''+current.number;
		ritmGr.update();
	}
})(current, previous);

Let me know if any issues

Dan Lewis
Giga Contributor

Hi,

Okay, that totally makes sense.

The script is trying to create a new RITM to update rather than update an existing RITM.  Is that possible?

I am guessing the new RITM is created by the "new GlideRecord" statement.  Yes?

How do I find an existing?

Thanks so very much for all you help.

Thank you,
Dan