Can we Make users to select the choice field (State Field ) in POP up message?

devservicenow k
Tera Contributor

My Requirement is To show a POP up message with the State choice Field, From that the user should choose the State fields by UI action through Testing Buttons.

On clicking the Testing Button, POP up Message should get displayed with State field , from that the user should select the choice, but other choices are not getting displayed , how tosolve this?

 

function onClick(g_form) {
    g_modal.showFields({
        title: "Enter your reason",
        fields: [{
            type: 'reference',
            name: 'state',
            label: getMessage('Reason'),
            mandatory: true,
            reference:'state',
            referringTable: 'incident',
            referringRecordId: g_form.getUniqueValue(),
            value: g_form.getValue('state'),
            displayValue: g_form.getDisplayValue('state'),
        }],
        size: 'lg'
    }).then(function(fieldValues) {
        g_form.setValue('state', fieldValues.updatedFields[0].value);
        g_form.save();
    });
}

what to change in script?

7 REPLIES 7

@devservicenow k 

For that you can use GlideAjax and check what value user selected in the choice

I believe I answered your original question of showing choices.

Please mark my response as correct and close the thread.

Regards
Ankur

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

Tried with GLideAjax but not working

 

function onClick(g_form) {

    var arr = [];
    var obj = {};
    obj["value"] = "1";
    obj["displayValue"] = "Unclear recommendations from Premex expert";
    arr.push(obj);

    var obj1 = {};
    obj1["value"] = "2";
    obj1["displayValue"] = "Unclear recommendations from InsP expert";
    arr.push(obj1);

    g_modal.showFields({
        title: "Enter your reason",
        fields: [{
            type: 'choice',
            name: 'u_query',
            label: getMessage('Reason'),
            mandatory: true,
            choices: arr
        }],
        size: 'lg'
    }).then(function(fieldValues) {
        
        g_form.setValue('u_query', fieldValues.updatedFields[0].value);
        g_form.save();
        
        var close_code = g_form.getValue("u_query");
        var opentasks = '';
    var ga_1 = new GlideAjax('IncidentTaskUtilsAjax');
    ga_1.addParam('sysparm_name', 'openTasksAvailable');
    ga_1.addParam('sysparm_incident', g_form.getUniqueValue());
    ga_1.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        opentasks = answer;
        if (close_code=="Unclear recommendations from Premex expert") {
            
                            var gr= new GlideRecord('sn_customerservice_task');
    gr.initialize();
    gr.short_description = current.short_description;
    gr.parent =current.sys_id;
    gr.insert();
    current.update();
    action.openGlideRecord(gr);
        }
                });
    
            
            
        });

}

Hi,

the glideAjax function should perform the insert but you are doing insert in the client script which is wrong

Also you cannot use current.update() in that

you can enhance your logic to move that code of insertion into that ajax function

I believe I answered your original question of showing choices.

Regards
Ankur

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