UI action redirection to previous page issue

KaMmILa__
Tera Expert

we have a UI action Cancel Task on workorder table when clicked it should make the reason for cancellation field mandatory and visible and if entered then it should set the state to cancel, but when I click on the UI action it is redirecting to the previously worked (used page) , not sure how to debug this and it is also not updating the record. 

Below is the UI policy to hide the field 

find_real_file.png

 

 

UI action : 

find_real_file.png

Script:

function checkReason() {
    g_form.setDisplay("u_cancel_reason", true);
    if (g_form.getValue('u_cancel_reason') == '') {
        g_form.setMandatory("u_cancel_reason", true);
        gs.addErrorMessage("a change task must be added before submitting the change");
        //alert('Please enter the reason before cancellation');
        return false;
    }

    gsftSubmit(null, g_form.getFormElement(), 'cancel'); // give the action name of your UI Action

}

if (typeof window == 'undefined')
    serverResolve();

function serverResolve() {
    new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
    //Moving redirect from state flow to UI action
    action.setRedirectURL(current);
}

 

When clicked on the UI action , cancel reason will be mandatory and if selected , there is a OOB in UI action which will enforce worknotes mandatory ,

This is the OOB code 

new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
//Moving redirect from state flow to UI action
action.setRedirectURL(current);

find_real_file.png

34 REPLIES 34

Maik Skoddow
Tera Patron
Tera Patron

Hi

I think you have to add the following line of code at the beginning of your function serverResolve()

current.update();

 

Regarding your redirect issue I am afraid I have not understood, what the target page should be after clicking the Cancel button.

It should remain on the same page, I update the code but still not working as expected.

When Cancel task UI action is clicked, the reason for cancellation is made mandatory and when I click on it again it should check if the worknotes is empty or not if empty it will be made mandatory as pet the code ( which is controlled in the state flow) but in my situation, it is redirecting to list view as the reason for cancellation is not empty.

Hi,

can you try this

function serverResolve() {
    new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
    //Moving redirect from state flow to UI action
    var url = '/' + current.getTableName() + '.do?sys_id=' + current.sys_id;
    action.setRedirectURL(url);
}

Regards
Ankur

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

Thanks, Ankur but for some reason, it is not setting the state to cancel, I mean  not updating the record