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

Aniket15
ServiceNow Employee
ServiceNow Employee

@ABC6 one way is to make the cmdb ci field mandatory and add the reference qualifier for cmdb ci field on incident as per your use case. Then clicking on the magnifier icon you will get appropriate list.

Or you can also have a declarative action on click of which you may want to launch a pop up with the list.

 

Or, you can associate the client script to launch a modal on gform events.

As Haseeb pointed out above this requirement needs to be implemented in SOW and canot be achieved by platform client scripts

ABC6
Tera Contributor

it is already working in native UI, wanna implement over SOW ,in an SOW it get open like above mentioned

Aniket15
ServiceNow Employee
ServiceNow Employee

To implement this in SOW you may need to use declarative actions, and via declarative action launch a modal, and define a page with the list component as you need and associate it with your modal. 

ABC6
Tera Contributor

I am new to this area, how can i achieve it, do i need to declare any kind of statement over client script or Script include.

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

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 ...