Is there any possible to get the previous value of a field using fix script or background script??

gokulraj
Giga Expert

Hi Team,

I have a requirement to close bulk records where the current state is "open" and the previous state is "closed complete".

I am unable to get the previous value of the field in fix script.

Is there any possible?

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

You can use sys_audit table to get old value. But this table is very big in the number of rows and might affect the performance of the system.

I have provided the code  for 1 user earlier which fetches the incidents based on old value. check the replies and you will find the code in this question.

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

You can use that as reference and can modify as per your requriement.

Mark the comment as a correct answer and also helpful if it helps.

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Gokulraj,

Directly it is not possible.

If the table is audited then you can get the details from history table i.e. for particular field what is current value and what is previous value

go to sys_history_line.list

search with lable as your field name

add query for old value as closed complete and new value as open

and set.table as your table name

sample url below: I have taken incident table for example:

https://instanceName.service-now.com/sys_history_line_list.do?sysparm_query=set.table%3Dincident%5Elabel%3DState%5Eold%3DClosed%20Complete%5Enew%3DOpen

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

asifnoor
Kilo Patron

Hi,

You can use sys_audit table to get old value. But this table is very big in the number of rows and might affect the performance of the system.

I have provided the code  for 1 user earlier which fetches the incidents based on old value. check the replies and you will find the code in this question.

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

You can use that as reference and can modify as per your requriement.

Mark the comment as a correct answer and also helpful if it helps.

Community Alums
Not applicable