UI Action for state update

SnowUser09
Tera Contributor

Hello All,
I am trying to update the state of the ticket with a button" moved to next state" based on the current state, using if else, like if current state is draft the state will update as assign, if current state is assign then state will be updated as Awaiting approval, if current state is awaiting approval then by clicking the button state will be updated as execution. 

I am able to set only one state by "g_form.setValue('state', xx);" but not able to use it to choose state based on current state, kind of to move the ticket in a flow. 

Can anyone help with any if else kind of statement, 

Thank you

1 ACCEPTED SOLUTION

Vaibhav
Mega Guru

Hello 

you can moved to next state using below script:

 

var state = current.getValue("state");

if (state == "1") { // form current state value
    current.state = "2"; // next state value to set
} 
else if (state == "2") {
    current.state = "2";
} 
else if (state == "3") {
    current.state = "2";
}
current.update();
action.setRedirectURL(current);

 

Mark as correct and helpful if it solved your query.

Regards,
Vaibhav

View solution in original post

4 REPLIES 4

Aman Kumar S
Kilo Patron

Why don't you refer to the state model of the the table and incorporate that in your script.

And you can do condition building, such as if current state is new, set the state as WIP and if current state is WIP , next state can be resolved...

 

Best Regards
Aman Kumar

Hi Aman, State model is there for the table but how to incorporate it in the script. 

can you share the script template or command that can be used, 

You can follow the state model how exactly it works, because its highly unlikely that your state flow is going to be straightforward and you should be making it robust so the UI action doesn't fail.

Go to State model in app navigator, you can find for each table which is conifgured and you can glide the table to make it more aligned with the system:

statemodel.PNG

Best Regards
Aman Kumar

Vaibhav
Mega Guru

Hello 

you can moved to next state using below script:

 

var state = current.getValue("state");

if (state == "1") { // form current state value
    current.state = "2"; // next state value to set
} 
else if (state == "2") {
    current.state = "2";
} 
else if (state == "3") {
    current.state = "2";
}
current.update();
action.setRedirectURL(current);

 

Mark as correct and helpful if it solved your query.

Regards,
Vaibhav