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 

The openCmdbCIList function in the Add UI Action for Affected CI is different.
Please see below.

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

gajax.getXMLAnswer(openList);
}

I tried updating the AssociateCIToOutage by adding this line of code in the  _getURL  function but it still did not work.

 url.set("sysparm_query", 'insert query here');

Thank you.

 

@ceraulo 

I could see both the UI Actions are calling same script include AssociateCIToTask and function getURL

ADD on Affected CI

find_real_file.png

ADD on Impacted CI

find_real_file.png

Regards
Ankur

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

@ceraulo 

I could see you marked my response as correct earlier and now it is not.

If my response helped please mark it correct

Regards
Ankur

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

My apologies, @Ankur Bawiskar . I marked your reply as correct by mistake.

Do you know why the condition in the Impacted CI is the same as Affected CI even if I added a different query to the Impacted CI Script Include than in the Affected CI Script Include?

Hi,

I could see the same script include and function being called from both the UI Actions.

Are you having different functions being called?

Regards
Ankur

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