Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to copy the previous value of the field to another field in the same table

Chandu12
Mega Expert

Hello Experts,

I need to copy the previous data of "total_Cost" field to "Previous_total_cost" field.

"total_cost" field type is of string type

Requirement is : Need to trigger an email if any changes happened to the "total_cost" field and in the body previous total cost should be there so i have created a field "previous_total_cost". but couldn't get the previous value of "total_Cost" field to "Previous_total_cost" field.

"Previous_total_cost" field will be not visible in the form.

 

So please suggest me how can i achieve this, any help would be appreciated.

 

Regards,

Chalan

1 ACCEPTED SOLUTION

Gaurav Bajaj
Mega Sage

Hi,

Please follow below points to make it work.

1) Create a before update BR which copies the value of total cost to previous total cost in case when total cost changes.

 

current.u_previous_total_cost = previous.total_cost.

 

2) Once you BR is ready, get the current values of your fields in the notification and it should do.( If you don't have a notification in place already, then you can create on record updated/through eventqueue.

 

Thanks

Gaurav

 

View solution in original post

5 REPLIES 5

User below condition in Before update business rule 

 

if(current.total_Cost.changes() && !current.total_Cost.nil() )
current.Previous_total_cost = previous.total_Cost;