"Create Normal Problem" UI Action on Incident to Create a Journal Entry Containing Change Number

Ben Vargas
Tera Guru

ServiceNow Support has taken the stance that modifying the "Create Normal Change" UI Action to set the comments journal field during save of incident.rfc (Related Records > Change Request field on Incident Default view) "involves customization and is beyond the scope of our ability to assist".

 

I would argue that Support is overreaching with this claim since this is a simple line just before GlideRecord update() method is called (out-of-box after they are setting incident.rfc). Further the GlideElement setJournalEntry() is a documented method in their developer portal, and it seems to be broken / not working...

 

https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/c_GlideElementAPI#r_Glide...

 

Regardless, we're left without support by ServiceNow and I'm wondering if anyone else has tackled this requirement successfully using the UI Action located here: <instance>/now/nav/ui/classic/params/target/sys_ui_action.do%3Fsys_id%3D30c9566dc61122740030e173564c1c74%26sysparm_record_target%3Dsys_ui_action

 

This is as simple as it gets, so I'm surprised by their refusal to support this...

Screenshot 2023-08-14 135249.png

I don't want to add a Business Rule on the change table to make the journal entry back because it would likely create a timing issue where the change is created triggering the business rule before the current.update() is completed by this UI Action. I could add a custom field to the change table to capture the source incident and use that to make the journal, but that seems like a bad practice because I'm then doing an extra update() to the incident while the UI Action ServiceNow has configured is also doing an update() ... unnecessary duplicate updates.

 

I could schedule a system event that then goes back from the created change to update the incident journal, but that feels like a hack to something that should be working out-of-box (using setJournalEntry just prior to ServiceNow's current.update() call).

 

Any ideas on this one community? All three approaches to setting the comments journal field on Incident fail in the "Create Normal Change" UI Action and I suspect it is caused by a scope issue with the change request insert running in the same block, but ServiceNow refuses to support this.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Hi @Ben Vargas  : Have you checked your script is going inside if block ?

 

Let me explain you, if you have plugin [ com.snc.change_management.standard_change_catalog ] activated then line number 28 "if" block will not work, it will execute line number 4 if block to set, rfc column.

 

You need to update the script inside the "out of the box" business rule to set the comments. 

 

Business rule name :  Link change to incident in Workspace

 

https://<YourInstanceURL>.service-now.com/sys_script.do?sys_id=5bed2de0235123001488dc1756bf65af&sysparm_view=&sysparm_domain=null&sysparm_domain_scope=null&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=nameSTARTSWITHLink+change+to+incident+in+Wkspace%5eORDERBYname

 

Updated Script: 

 

(function executeRule(current, previous /*null when async*/) {
	var session = gs.getSession();
	var linkData = session.getProperty('change_link');
	session.clearProperty('change_link');
	
	if (linkData) {
		
		var taskGr = new GlideRecord(linkData.table);
		if (taskGr.get(linkData.sysid)) {
			var incUrl = "<a href='" + taskGr.getLink() + "'>" + taskGr.getDisplayValue() + "</a>";
			taskGr.setValue(linkData.field, current.getUniqueValue());
			taskGr.comments.setJournalEntry('New Normal Change Created: '+current.getValue('number')); // This line will add comments on incident.
			var updated = taskGr.update();

			//Return if in Workspace do not show message as is shows on wrong tab
			if (linkData.isWorkspace)
				return;

			if (updated)
				gs.addInfoMessage(gs.getMessage("{0} Change {1} created from {2}", [current.getDisplayValue('type'),  current.getDisplayValue(), incUrl]));
			else
				gs.addInfoMessage(gs.getMessage("{0} Change could not be created from {1}", [current.getDisplayValue('type'), incUrl]));
		}
	}

})(current, previous);

 

 

Let me know if you have any further questions for me. 

 

Thanks,

Harsh

 

If my answer helped you, kindly accept the solution and close this thread. 

 

View solution in original post

2 REPLIES 2

Harsh Vardhan
Giga Patron

Hi @Ben Vargas  : Have you checked your script is going inside if block ?

 

Let me explain you, if you have plugin [ com.snc.change_management.standard_change_catalog ] activated then line number 28 "if" block will not work, it will execute line number 4 if block to set, rfc column.

 

You need to update the script inside the "out of the box" business rule to set the comments. 

 

Business rule name :  Link change to incident in Workspace

 

https://<YourInstanceURL>.service-now.com/sys_script.do?sys_id=5bed2de0235123001488dc1756bf65af&sysparm_view=&sysparm_domain=null&sysparm_domain_scope=null&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=nameSTARTSWITHLink+change+to+incident+in+Wkspace%5eORDERBYname

 

Updated Script: 

 

(function executeRule(current, previous /*null when async*/) {
	var session = gs.getSession();
	var linkData = session.getProperty('change_link');
	session.clearProperty('change_link');
	
	if (linkData) {
		
		var taskGr = new GlideRecord(linkData.table);
		if (taskGr.get(linkData.sysid)) {
			var incUrl = "<a href='" + taskGr.getLink() + "'>" + taskGr.getDisplayValue() + "</a>";
			taskGr.setValue(linkData.field, current.getUniqueValue());
			taskGr.comments.setJournalEntry('New Normal Change Created: '+current.getValue('number')); // This line will add comments on incident.
			var updated = taskGr.update();

			//Return if in Workspace do not show message as is shows on wrong tab
			if (linkData.isWorkspace)
				return;

			if (updated)
				gs.addInfoMessage(gs.getMessage("{0} Change {1} created from {2}", [current.getDisplayValue('type'),  current.getDisplayValue(), incUrl]));
			else
				gs.addInfoMessage(gs.getMessage("{0} Change could not be created from {1}", [current.getDisplayValue('type'), incUrl]));
		}
	}

})(current, previous);

 

 

Let me know if you have any further questions for me. 

 

Thanks,

Harsh

 

If my answer helped you, kindly accept the solution and close this thread. 

 

Bingo! You nailed it, thank you for the sanity check... I should have caught that, or support! 🙂