Script to update existing related records

surajjha
Tera Contributor

Dear leaders ,

Can someone please help me with script for updating related records Description in Risk statement.

below 2 screen shots are GRC risk statement and related list have risks.

We have requirement to update all risk description if risk statement description is changed.

1>

find_real_file.png

 

2>

find_real_file.png

 

Thanks in advance.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@surajjha 

you can use these steps

1) Always use after update BR on table "sn_risk_definition" to update records on another table

Condition: Description Changes

Script:

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

	// Add your code here
	var gr = new GlideRecord("sn_risk_risk");
	gr.addQuery("statement", current.getUniqueValue());
	gr.query();
	while(gr.next()) {
		gr.setValue('description', current.getValue('description'));
		gr.update();
	}

})(current, previous);

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

13 REPLIES 13

Thank you for sharing. Its good to get your complete library which you might have collected in last 4 years 😛

Regards,
Prasad

Hmm..

Sometimes we miss those possibly because the links/files get deleted over period of time.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur.

Kartik Choudha1
Tera Guru

Hi Ankur,

 

Why to use only After Br and not Async BR. Any particular reason for that