Need help in UI Action

Mishu
Tera Expert

Hello Experts,

 

I created a UI Action where the answer for a choice field is Yes it should bring a UI Page as a pop-up and insert the record in a particular table. 

 

Below is the script i wrote, my script is not reading the value yes or no in the choice field.

 

Could somebody please advice what is wrong in below script?

 

 

function CheckReversal() {
    g_form.setMandatory('reversal_error', true);
    gsftSubmit(null, g_form.getFormElement(), 'reversal');
}
if (typeof window == 'undefined')
    DoReversal();
function DoReversal() {
    if (current.getValue('reversal_error') == 'yes') {
        var tableName = "x_nuv_rejection_details";
        var sysID = g_form.getUniqueValue();
        var prd = g_form.getValue('period');
        var seg = g_form.getValue('segment');

        //Create and open the dialog form
        var dialog = new GlideDialogForm('Rejection Details', tableName); //Provide dialog title and table name
        dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record
        dialog.addParm('sysparm_view', 'Default View'); //Specify a form view
        dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
        dialog.setLoadCallback(function(iframeDoc) {
            // To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
            var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;

            dialogFrame.g_form.setValue('nuv_ticket', sysID);
            dialogFrame.g_form.setValue('period', prd);
            dialogFrame.g_form.setValue('segment', seg);
            dialogFrame = null;
        });
        dialog.render(); //Open the dialog
    } else {
        var reversalRec = new x_nuv_rejection_detailActivitiesUtil().createReversal();
        action.setRedirectURL(reversalRec);
    }
}

 

 

24 REPLIES 24

Mishu
Tera Expert

Could somebody please help ?

Ankur Bawiskar
Tera Patron
Tera Patron

@Mishu 

use this

function CheckReversal() {

    var tableName = "x_nuv_rejection_details";
    var sysID = g_form.getUniqueValue();
    var prd = g_form.getValue('period');
    var seg = g_form.getValue('segment');
    if (g_form.getValue('reversal_error') == 'yes') {

        //Create and open the dialog form
        var dialog = new GlideDialogForm('Rejection Details', tableName); //Provide dialog title and table name
        dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record
        dialog.addParm('sysparm_view', 'Default View'); //Specify a form view
        dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
        dialog.setLoadCallback(function(iframeDoc) {
            // To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
            var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;

            dialogFrame.g_form.setValue('nuv_ticket', sysID);
            dialogFrame.g_form.setValue('period', prd);
            dialogFrame.g_form.setValue('segment', seg);
            dialogFrame = null;
        });
        dialog.render(); //Open the dialog

        g_form.setMandatory('reversal_error', true);
        gsftSubmit(null, g_form.getFormElement(), 'reversal');
    } else {
        // reload
    }
}

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

function DoReversal() {
    var reversalRec = new x_nuv_rejection_detailActivitiesUtil().createReversal();
    action.setRedirectURL(reversalRec);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thanks for your response but now on clicking nothing is happening, even the field for which I have to select Yes/No is also not becoming mandatory on clicking the button....Button is not working at all 

@Mishu 

share your UI action configuration screenshot

It should be marked as Client=True with onclick function

did you check what came in alert?

function CheckReversal() {

    var tableName = "x_nuv_rejection_details";
    var sysID = g_form.getUniqueValue();
    var prd = g_form.getValue('period');
    var seg = g_form.getValue('segment');
    if (g_form.getValue('reversal_error') == 'yes') {
        alert('inside');
        //Create and open the dialog form
        var dialog = new GlideDialogForm('Rejection Details', tableName); //Provide dialog title and table name
        dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record
        dialog.addParm('sysparm_view', 'Default View'); //Specify a form view
        dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
        dialog.setLoadCallback(function(iframeDoc) {
            // To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
            var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;

            dialogFrame.g_form.setValue('nuv_ticket', sysID);
            dialogFrame.g_form.setValue('period', prd);
            dialogFrame.g_form.setValue('segment', seg);
            dialogFrame = null;
        });
        dialog.render(); //Open the dialog

        g_form.setMandatory('reversal_error', true);
        gsftSubmit(null, g_form.getFormElement(), 'reversal');
    } else {
        // reload
    }
}

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

function DoReversal() {
    var reversalRec = new x_nuv_rejection_detailActivitiesUtil().createReversal();
    action.setRedirectURL(reversalRec);
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader