Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to redirect to same page when click on Approve button

Rama Rao
Tera Contributor

Hello,

 

I want to be redirected to the same page when click on E- signature approve button. Is that possible?

 

note: currently it redirects to previous update page

 

Thanks in advance.

11 REPLIES 11

@Rama Rao 

If you are using client side then we can use the GlideAjax API to call a server-side script include that performs the update and then reload the form.

UI action:

 

function onApproveClick() {
    var sysID = '';
    if (gel('sys_uniqueValue'))
        sysID = gel('sys_uniqueValue').value;

    var ga = new GlideAjax('ESignatureUtils');
    ga.addParam('sysparm_name', 'listApprovalCheck');
    ga.addParam('sysparm_target_state', 'approved');
    ga.addParam('sysparm_sys_ids', sysID);

    ga.getXMLAnswer(function(answer) {
        if (answer == "prompt_v2") {
            displayGreyout();
            promptCheck(true, 'approve', function(doPrompt, sysID) {
                if (doPrompt != "true") {
                    processFormUpdateApprovalCheck("no_prompt", sysID, "sysverb_update");
                } else {
                    g_form.previousState = g_form.getValue("state");
                    g_form.setValue("state", "approved");
                    processFormUpdateApprovalCheck("prompt_v2", sysID, "sysverb_update");
                }
            }, sysID);
        } else {
            g_form.previousState = g_form.getValue("state");
            g_form.setValue("state", "approved");

            var gaUpdate = new GlideAjax('CustomApprovalUtils');
            gaUpdate.addParam('sysparm_name', 'approveRecord');
            gaUpdate.addParam('sysparm_sys_id', sysID);
            gaUpdate.getXMLAnswer(function(response) {
                if (response == "success") {
                    // Reload the current form to reflect changes
                    g_form.refresh();
                } else {
                    // Handle error
                    alert('Approval failed: ' + response);
                }
            });
        }
    });
}

 

Script Include:

 

 approveRecord: function() {
        var sysID = this.getParameter('sysparm_sys_id');
        var gr = new GlideRecord('sysapproval_approver');
        if (gr.get(sysID)) {
            gr.setValue('state', 'approved');
            gr.update();
            return 'success';
        } else {
            return 'failure';
        }
    }

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Hi @Maddysunil ,

I have tried the above code and not working as expected. after entered the credintials, it redirects to other pages. any other suggestions