How to access previous value of "state" field in workflow

Roshani
Tera Expert

Hi All,

I have a workflow running on HR payroll table . I want to set the "state" field to its previous value . How can I write in workflow . Below code i am using now, its seems not working 

current.state = workflow.scratchpad.state;
current.update();

10 REPLIES 10

Shivani Singh1
Tera Guru

Hi Roshani,

Simply use previous.state directly whenever you want to set it.

 

Please mark helpful & accept the solution if it solves the purpose.

Hi Shivani ,

Please see below this is not working 

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

@Roshani 

you cannot access previous object in workflow

it only works in business rules

1) store the value before you update in workflow scratchpad and then use it

Regards
Ankur

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

@Roshani 

another option to get the previous value is using sys_audit table which stores the information

script help check below link

https://community.servicenow.com/community?id=community_question&sys_id=06d2e119db7323c0fece0b55ca96...

Regards
Ankur

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