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

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.

So, I have this requirement to go back to the previous state when clicked on a button. I used your code for that and using that the form is going to the previous state. Now, when the user makes any changes in that state and clicks on submit to go to the next state, it is inserting another record with same incident number but with the next state.

Since it is the functionality of the submit button to insert a new record, it is doing that, I understand. But in my case, I don't want to create a new record when the button is clicked in the second time. I want the changes to be made in the same record. 

 

Can you please help me with this?

cloudminus89
Mega Contributor

slightly clunky way and perhaps not ideal, but it works

navigate to the history entry. the sysid corresponds to the id of the record changed

var grSHS=new GlideRecord('sys_history_set');//--record history
if (grSHS.get('id', '8cf2d354db733f403c304662159619a2')){
var grSHL=new GlideRecord('sys_history_line');//--history
grSHL.addQuery('field', 'assignment_group'); //--or whatever field has changed
grSHL.addQuery('set', grSHS.sys_id);
grSHL.addQuery('oldISNOTEMPTY^newISNOTEMPTY');
grSHL.orderByDesc('sys_created_on');
grSHL.query();
while(grSHL.next()){
  gs.print(grSHL.sys_id);
  gs.print(grSHL.old);
  gs.print(grSHL.old_value);
}
}