How can i get Previous state value by using of UI Action

Rakhesh
Kilo Guru

Hi All,

I have a issue., we have a "status" choice field. We are giving a option to change the "status" to requester in ITIL view.

And we removed the options example : when the status is 'working in progress' we are removing all choice values  but we are giving a 'close' choice option in every status for selecting. When requester selecting close option Reopen form button is visible.

i when i'm selecting reopen button i want to state should be previous state value.

How to do this scenario??

Regards,

Rakesh

1 ACCEPTED SOLUTION

Ok here is the changes you need to do:

Write BR: OnBefore and condition State = Changes

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

var prevalue = previous.state;
current.setValue('u_previous_state', prevalue);

})(current, previous);

 

After that write the UI Action code:

var preval = current.u_previous_state;

current.state = preval;
current.update();
action.setRedirectURL(current);

find_real_file.png

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

View solution in original post

7 REPLIES 7

Harish KM
Kilo Patron
Kilo Patron

Check this

you cannot get the previous value in UI ACtion

for more info below

https://community.servicenow.com/community?id=community_question&sys_id=376ec321dbdcdbc01dcaf3231f9619df

Regards
Harish

Shashikant Yada
Tera Guru

Hi,

 

You can create one new field "Previous state" and store the value in it whenever state changes.

In UI Action, you can write the script:

current.state = current.u_previuos_state;

current.update;

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

Hi shashikantyadav,

 

Thanks for your attention!!

 

yes i followed your suggestion and i created one field and i passed the state value when the state is changes.

but when i changed the state value into close the  it passed the close value but i want to update it as previous value

 

Hi,

You will write code like this in ui action

current.state=current.u_previuos_state

current.update();