How to update a field value on other table field which is a reference field on current table.

Pravallika14
Tera Contributor

Hello Team,

I have a reference field ("") on Problem ticket, which has an Incident Number (PFA) from Incident table. I want to set the value of "Contact type" field to "None" on Incident Form of this old Incident, whenever the Incident Number changes to a new incident on Problem ticket form.

find_real_file.png

find_real_file.png

 

Please help me on how to capture the SysID of the previous incident in "o set the value of  "Contact type" field to "None" on the Previous incident .

I wanted to use , Before Business rule for the same. But I am not sure how can we capture the previous values of a reference field using previous object .

 

Thank you!!

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Musab Rasheed
Tera Sage
Tera Sage

Hi Pravalika,

Write After business rule on problem table like below

find_real_file.png

 

Condition :

current.first_reported_by_task != previous.first_reported_by_task

Code :

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

	gs.addInfoMessage('Current '+ current.first_reported_by_task + ' Previous '+ previous.first_reported_by_task);
	// Add your code here
	var gr = new GlideRecord('incident');
	gr.addQuery('sys_id', previous.first_reported_by_task);
	gr.query();
	if(gr.next())
		{
			gs.addInfoMessage("Going inside");
			gr.contact_type = '';
			gr.update();
		}

})(current, previous);

 

Screenshot of condition and code :

find_real_file.png

 

Mark my answer as correct or hit like

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

4 REPLIES 4

The SN Nerd
Giga Sage
Giga Sage

If you are not familiar with coding, you could achieve this using Flow Designer.

 

Trigger: Problem is updated

Condtion: First reported by changes and Firest reported by is not empty

  • Action:Update Record (Problem.First reported by)
    • Contact type = none

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

The SN Nerd
Giga Sage
Giga Sage

If you are set on business rules, you must use an after rule.

It is generally considered best practice to consider low/no code approaches first.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Musab Rasheed
Tera Sage
Tera Sage

Hi Pravalika,

Write After business rule on problem table like below

find_real_file.png

 

Condition :

current.first_reported_by_task != previous.first_reported_by_task

Code :

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

	gs.addInfoMessage('Current '+ current.first_reported_by_task + ' Previous '+ previous.first_reported_by_task);
	// Add your code here
	var gr = new GlideRecord('incident');
	gr.addQuery('sys_id', previous.first_reported_by_task);
	gr.query();
	if(gr.next())
		{
			gs.addInfoMessage("Going inside");
			gr.contact_type = '';
			gr.update();
		}

})(current, previous);

 

Screenshot of condition and code :

find_real_file.png

 

Mark my answer as correct or hit like

Please hit like and mark my response as correct if that helps
Regards,
Musab

Musab Rasheed
Tera Sage
Tera Sage

Hi,

If your issue is resolved, Please mark my answer as correct and close the thread.

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab