Client Script in Incident form

Vengeful
Mega Sage

I received a requirement that in the incident form, if Subcategory 1 (u_subcategory) is SAP, only APO, ECC, OpenText, and SAP-Security should be shown in the CI field.

Vengeful_1-1715756545825.png

 

I created a Client Script, but there's an error: onChange script error: TypeError: g_form.setDependentField is not a function function () { [native code] }

 

Client Script:

Vengeful_2-1715756631901.png

 

 

 

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

You will need to adjust this in the reference qualifier of the cmdb_ci field. Add a check to the subcategory field and limit the choices.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

5 REPLIES 5

Mark Manders
Mega Patron

You will need to adjust this in the reference qualifier of the cmdb_ci field. Add a check to the subcategory field and limit the choices.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders 
How can I achieve that? Since there are other Category and Subcategory that using the CI field.

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Vengeful ,

As suggested by @Mark Manders  you need to edit the reference qualifier to return only specificed CIs in Config item field.

 

Create a script include which returns only 'SAP, only APO, ECC, OpenText, and SAP-Security' realted  CIs if the category is relevent to it.

 

start with script include and reference qualifier and let us know were your struck...


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Here is the Script Include

Vengeful_0-1715830432863.png

Client Script

Vengeful_1-1715830511342.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    // Get the value of the u_subcategory field
    var subcategory = g_form.getValue('u_subcategory');
    // Check if the u_subcategory is SAP
    if (subcategory.toLowerCase() === 'sap') {
        // Call the Script Include to get relevant CIs
        var ga = new GlideAjax('FilterCIsByCategorySAP');
        ga.addParam('sysparm_name', 'getRelevantCIs');
        ga.addParam('sysparm_subcategory', subcategory);
        ga.getXMLAnswer(function(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            var ciList = JSON.parse(answer);
            // Create a query to limit the CI field
            var ciQuery = 'sys_idIN' + ciList.map(function(ci) {
                return ci.sys_id;
            }).join(',');
            g_form.setQuery('cmdb_ci', ciQuery);
        });
    } else {
        // Clear the query if the subcategory is not SAP
        g_form.clearOptions('cmdb_ci');
    }
}

 

This is the dictionary of Configuration Item in Incident form

Vengeful_2-1715830562137.png