How to make the BR script shorter

VIKAS MISHRA
Tera Contributor

we have 20 different field in the project record form and all 20 fields are used to saved one integer number field name such as "OPEX Internal Order 1" and whenever some one add any integer number to these fields it auto create the record in another io number table , basically per field per record creation happen.

but there is no code to delete those record from io number one you remove from the project record. 

Below is my BR script which is using to delete the record from IO number table once we remove that number from project record. but this code is only for 1 field, now i am worried that if i write same code for 20 fields it will become a very lengthy code, could you please suggest the shortest way to write script for another 19 fields that will be merged here.

 

I need to perform the same task for another 19 fields similar to the field "u_ca_internal_order_2"

 

 

 

 

if (current.u_ca_internal_order_2.changesTo('')) {
        var previousIo = previous.u_ca_internal_order_2;
		var gr = new GlideRecord('u_io_number');
		gr.addQuery('u_io_value', previousIo);
		//gr.addQuery('u_project_number', current.number);
		gr.query();
		while (gr.next()) {
               gr.deleteRecord()
}

 

 

 

 

1 REPLY 1

Najmuddin Mohd
Mega Sage

Hello @VIKAS MISHRA ,

You can store all these field names in a system property and loop through it to get the names of all those fileds.

You can have the business rule with conditions After Update, and loop through variables.

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.