List View of Ci need to populate in Modal based upon caller Ci

ABC6
Tera Contributor

Hello Team,
I have a requirement where i need to pull the ci information based upon Caller Ci,for this i did create a script include and client script to achieve but it only shows the CI name , want list view of CI based upon caller info.

 if (g_form.getViewName() == 'sow' || g_form.getViewName() == 'sow_new_record') {


        if (g_form.isNewRecord()) {
            alert("1 IFF");
            getCICaller();
        } else if (!g_form.isNewRecord() && newValue != oldValue && g_form.getValue('cmdb_ci') == '') {
         
            getCICaller();
            return;
        } else if (!g_form.isNewRecord() && newValue != oldValue) {
        
            if (g_form.getValue('cmdb_ci') != '') {
                return;
            }

        }
        alert("TestOut");
    }
}

function getCICaller() {
    g_form.clearValue('cmdb_ci');
    var callerId = g_form.getValue('caller_id');
    // Make a GlideAjax call to fetch CI choices based on the caller ID
    var ga = new GlideAjax('GetCIsForUser');
    ga.addParam('sysparm_name', 'getCIs');
    ga.addParam('caller_id', callerId);
    ga.getXMLAnswer(_response);

    function _response(response) {

        var ciList = JSON.parse(response);
        // Clear existing options in CI field
        g_form.clearValue('cmdb_ci');

        // Populate CI field with fetched CIs
        if (ciList.length == 1) {
            alert("CI LIST:" + ciList[0].sys_id);
            alert("CI LIST22:" + ciList[0].name);
            alert("Message:" + JSON.stringify(ciList));
            g_form.setValue('cmdb_ci', ciList[0].sys_id);
        }
        if (ciList.length > 1) {
            // Open a modal dialog with type 'choice' and show options
            var fields = [{
                type: 'choice',
                name: 'cmdb_ci',
                label: 'Select Configuration Item',
                choices: ciList.map(function(ci) {
                    return {
                        value: ci.sys_id,
                        displayValue: ci.name
                    };
                }),
                mandatory: true
            }];

            g_modal.showFields({
                title: 'Select Configuration Item',
                fields: fields,
            }).then(function(fieldValues) {

                g_form.setValue('cmdb_ci', fieldValues.updatedFields[0].value);

            });

        }





    }
}
 
ABC6_0-1711621123129.png



I need the Display Popup in List View not like above ,please help me to get this issue resolved

1 ACCEPTED SOLUTION

Aniket15
ServiceNow Employee
ServiceNow Employee

You may try this vide tutorial on how similar things work in configurable workspace like SOW. In the tutorial they have used CSM FSM workspace as an example.
https://www.youtube.com/watch?v=E9FhNpk0Mwk

View solution in original post

In this video I show you how you can configure a button in a Configurable Workspace to open a modal with a Next Experience component or page which you've designed in UI Builder. #servicenow #uibuilder Blog post: https://jessems.com/opening-modal-from-a-record-in-configurable-workspaces Preceding ...
9 REPLIES 9

Haseeb-Ahmed
ServiceNow Employee
ServiceNow Employee

Hi @ABC6 ,

you may not be able to achieve this with g_modal in the configurable workspace

please elaborate on the requirements like - on which interaction you want to show the modal etc.

 

I wanna show this model on basis of caller who has multiple CI associated with it and once we get select the caller details in incident a popup should appear and based upon CI detail will proceed further

Haseeb-Ahmed
ServiceNow Employee
ServiceNow Employee

popup should be open on which interaction? on click of any button or CI field search?

when we select caller in the caller field then based upon caller need to open a popup which has all detail of CI associated with the caller if they have multiple CI assignee