Abort submission and remain on the same page on UI Action if condition not met.

Apurva Jogal
Kilo Sage

Hi

I have created a UI Action with following script :

 

assignToMe();

function assignToMe() {

    if (!gs.getUser().isMemberOf(current.assignment_group.toString())) {
        gs.addErrorMessage('You cannot perform this action as you are not a member of Assignment Group ' + current.assignment_group.getDisplayValue());
        current.setAbortAction(true);
        //return false;
    } else {
        current.assigned_to = gs.getUserID();
        current.update();
        action.setRedirectURL(current);
    }

}
 
 
Above script is redirecting to same page, but after updating the record without saving the data added.
I want the data to remain same even if the action is aborted.
Basically nothing should happen apart from the error message.
 

Thanking you in advance.
1 ACCEPTED SOLUTION

Marcos Kassak
Kilo Sage
Kilo Sage

Hi @Apurva Jogal,

 

Try this and let me know:

 

 

function assignToMe() {
    if (!gs.getUser().isMemberOf(current.assignment_group.toString())) {
        gs.addErrorMessage('You cannot perform this action as you are not a member of Assignment Group ' + current.assignment_group.getDisplayValue());
        current.setAbortAction(true);
    } else {
        current.assigned_to = gs.getUserID();
        action.setRedirectURL(current);
    }
}

 

 

If you found my answer helpful or correct ✔️ in any way, please don't forget to mark it to help future readers! 👍

 

--

 

Kind regards,


Marcos Kassak
Solution Consultant  🎯

View solution in original post

2 REPLIES 2

Marcos Kassak
Kilo Sage
Kilo Sage

Hi @Apurva Jogal,

 

Try this and let me know:

 

 

function assignToMe() {
    if (!gs.getUser().isMemberOf(current.assignment_group.toString())) {
        gs.addErrorMessage('You cannot perform this action as you are not a member of Assignment Group ' + current.assignment_group.getDisplayValue());
        current.setAbortAction(true);
    } else {
        current.assigned_to = gs.getUserID();
        action.setRedirectURL(current);
    }
}

 

 

If you found my answer helpful or correct ✔️ in any way, please don't forget to mark it to help future readers! 👍

 

--

 

Kind regards,


Marcos Kassak
Solution Consultant  🎯

Hi thank you for this solution. it works well in service portal however not working in Interceptor (internal portal). Do you know what should I add to be able to works in interceptor as well?