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
Kilo 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

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

So here what you have to do is:

1) Create a Onchange client script on Total Cost field which will call the Script include. In this client script pass the OldValue parameter to script include

2) In script include you have to query this table and then you have to update the previous total cost field from backend.

3) Once the field is updated then you have to trigger a event which will trigger a notification.

Let me know if you want script.


Thanks,
Ashutosh Munot

Hi,

 

If you want to save Total cost to previous cost field immediately once you change total cost then you have to use Onchange script. If you dont want to do that then you have to use BR.


It will update the Previous cost field with total cost previous value and in the same BR you can trigger a event.


See below scrpit: Condition will be Total Cost Changes

current.previous_total_cost = previous.total_cost;

gs.eventQueue('eventname',current);

 

Then create a notification which will trigger only after event is fired.


Thanks,
Ashutosh

Hi,

I am new to Service Now and will be very much interested in understanding the steps mentioned by you. Can u please provide the script for my understanding?

Regards

Lakshmi

 

Gaurav Bajaj
Kilo 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