Before Business Rule to copy a field value to another custom field

Anmol Soldier
Tera Contributor

I want to copy a field value to a custom field before insert.

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Anmol Soldier 

Then you can write one line of code as below in before insert BR:-

 

current.youCustomField=current.yourMainField;

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

3 REPLIES 3

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Anmol Soldier 

Then you can write one line of code as below in before insert BR:-

 

current.youCustomField=current.yourMainField;

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Community Alums
Not applicable

Hi @Anmol Soldier ,

You can use this sample script :

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

	var gr = new GlideRecord("u_hardware_expensed_asset_list");
	gr.initialize();
	gr.<field_name1> = current.<field_name1>;
	gr.<field_name2> = current.<field_name2>;
	gr.<field_name3> = current.<field_name3>;
	//repeat above for all the required fields
	gr.update();

})(current, previous);

johnfeist
Mega Sage

Hi Anmol,

Based on your description, this is pretty simple.  Assuming that both fields are part of the same record, your rule would look like this:

current.setValue(<custom field to be updated>, <existing field with the value>);

If you need to put or get the value from some other record, just declare the GlideRecord and position before setting the value.

Because you are doing this in a Before rule, do not include current.update() in your rule otherwise you risk crating an endless loop.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster