Change the condition for Affected CIs and Impacted Services/CIs Related Lists

ceraulo
Mega Guru

Hello!

In the Change Request, there are Affected CIs and Impacted Services/CIs related lists. I want to change the condition that displays the CIs when clicking the Add button. How do I do this? And can this apply only to Change Requests?

find_real_file.png

 

Please help!

Thanks.

 

1 ACCEPTED SOLUTION

@ceraulo 

Both the UI Actions Add call the same script include function

You can pass extra parameter in each and determine which UI Action was clicked and accordingly apply necessary filter conditions

for the UI Action ADD present on Affected CI

function openCmdbCIList(){
    var gajax = new GlideAjax("AssociateCIToTask");
    gajax.addParam("sysparm_name","getURL");
    gajax.addParam("sysparm_id", g_form.getUniqueValue());
    gajax.addParam("sysparm_add_to", "task_ci");

    gajax.addParam("sysparm_from", "Affected CI");

    gajax.getXMLAnswer(openList);
}

For the UI Action ADD present on Impacted CI

function openCmdbCIList(){
    var gajax = new GlideAjax("AssociateCIToTask");
    gajax.addParam("sysparm_name","getURL");
    gajax.addParam("sysparm_id", g_form.getUniqueValue());
    gajax.addParam("sysparm_add_to", "task_ci");

    gajax.addParam("sysparm_from", "Impacted CI");

    gajax.getXMLAnswer(openList);
}

Now update the Script Include both the functions as this to differentiate

changes in bold

ajaxFunction_getURL: function(){
        var chgReqId = this.getParameter("sysparm_id");
        var addToTable = this.getParameter("sysparm_add_to") + "";
        var comingFrom = this.getParameter("sysparm_from");
        return this._getURL(chgReqId, addToTable,comingFrom);
    },

_getURL: function(chgReqId, addToTable, comingFrom){
        this.removeUserFilter();

        var latestClassAdded;
        var parentClass = "";
        var principalClassFilter = "";
        // latestClassAdded logic
        // 1. if there are ci's, get the latest class of the ci
        // 2. default the latest class to parent class
        if (addToTable === "task_ci") {
            principalClassFilter = this.getPrincipalClassFilter(chgReqId);
            if (!principalClassFilter)
                latestClassAdded = this.getLatestClass(chgReqId);
            parentClass = this.getParentClass(chgReqId);
            if (!latestClassAdded)
                latestClassAdded = parentClass;
        }
        else if (addToTable === "task_service_offering")
            latestClassAdded = "service_offering";
        else
            latestClassAdded = "cmdb_ci";

        var serviceOfferingFilter = (addToTable === "task_service_offering") ? "" : "sys_class_name!=service_offering";

        var fixedQuery = serviceOfferingFilter;
        if (principalClassFilter.length > 0)
            fixedQuery += '^' + principalClassFilter;

        if(comingFrom == 'Impacted CI'){
            // query for Impacted CI
        }
        else if(comingFrom == 'Affected CI'){
            // query for Affected CI
        }
        
        var url = new GlideURL("task_add_affected_cis.do");
        url.set("sysparm_crSysId", chgReqId);
        url.set("sysparm_view", "associate_ci");
        url.set("sysparm_add_to", addToTable);
        url.set("sysparm_stack", "no");
        url.set("sysparm_table", latestClassAdded);
        url.set("sysparm_parent_class", parentClass);
        url.set("sysparm_fixed_query", fixedQuery);
        return url;
    },

Regards
Ankur

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

View solution in original post

13 REPLIES 13

@Ankur Bawiskar 

I reviewed the UI Actions in our instance and I incorrectly updated the UI action for Affected CIs. I followed your script and it worked.

Thank you.

@ceraulo 

Glad to help.

Please mark appropriate response helpful as well.

Regards
Ankur

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

Hi @Ankur Bawiskar, related to this, how would we get the info to the script include from which table the Affected CI "Add" button was pressed from? For example, if I would need to introduce different filter to problem table than change table.

Hi,

you need to check the UI action and that would tell you the script include function.

You can pass extra parameter in each and determine from where UI Action was clicked and accordingly apply necessary filter conditions.

send the current table name using g_form.getTableName() as parameter

Regards
Ankur

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