Where can I find UI action for 'Add all' button on Configuration Item sys pop-up

harinalamalapu
Giga Expert

Hello friends,

Where can I find the UI action (I assumed it must be an UI action) corresponding to 'Add all' button on Configuration Item sys pop-up which was launched by clicking the 'Add' button on Affected CIs related list on a Change Request. It is basically to choose and add the CIs to a Change Request. Provided a screenshot of it below.

find_real_file.png

Thanks,

Hari

1 ACCEPTED SOLUTION

LaurentChicoine
Tera Guru

Your Add button on change_request is this UI Action https://<instance_name>.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=77688cfe6f35f100e5f2b3312e3ee4e6



Which refers to the Script Include you were talking about (AssociateCIToTask) and calls the function getURL(). This function returns a UI Page URL containing the right parameters to render the list and its UI Action. The UI Page is task_add_affected_cis.do which is a page that you can't edit or see source code in SNOW. This page is used to create a GlideOverlay (the window that opens).



So the Add All button itself is contained in this page and not editable.



Depending on what you want to do, I found using my developer console, the client script being called by the add all button:



function addAllToTask() {


        var g_list = GlideList2.get(NOW.task_add_affected.TABLE_NAME);


        var gajax = new GlideAjax("AssociateCIToTask");


        gajax.addParam("sysparm_name","addAll");


        gajax.addParam("sysparm_id", NOW.task_add_affected.TASK_ID);


        gajax.addParam("sysparm_query", g_list.getQuery());


        gajax.addParam("sysparm_tableName", g_list.tableName);


        gajax.addParam("sysparm_add_to_table", NOW.task_add_affected.ADD_TO_TABLE);


        gajax.getXMLAnswer(closeWindow);


}



Depending on your goal you could try to work out the addAll function in the script include to be able to use it based on what you want to do. This would be if you would like to use it somewhere else.



If you want to change the behavior of the Add all button, you could try to rebuild the UI page to have a custom one with your custom button. Or you could modify what the addAll function does inside the Script Include by customizing it (you can't extend it or copy it as the call to the function is hard coded in the UI page you can't modify).


View solution in original post

14 REPLIES 14

harinalamalapu
Giga Expert

I was able to reach trace a Script Includes 'AssociateCIToTask' which is having 'addAll' function. But I can't find who uses this function. Any help in identifying the code that handles this 'Add all' button will be appreciated.


LaurentChicoine
Tera Guru

Your Add button on change_request is this UI Action https://<instance_name>.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=77688cfe6f35f100e5f2b3312e3ee4e6



Which refers to the Script Include you were talking about (AssociateCIToTask) and calls the function getURL(). This function returns a UI Page URL containing the right parameters to render the list and its UI Action. The UI Page is task_add_affected_cis.do which is a page that you can't edit or see source code in SNOW. This page is used to create a GlideOverlay (the window that opens).



So the Add All button itself is contained in this page and not editable.



Depending on what you want to do, I found using my developer console, the client script being called by the add all button:



function addAllToTask() {


        var g_list = GlideList2.get(NOW.task_add_affected.TABLE_NAME);


        var gajax = new GlideAjax("AssociateCIToTask");


        gajax.addParam("sysparm_name","addAll");


        gajax.addParam("sysparm_id", NOW.task_add_affected.TASK_ID);


        gajax.addParam("sysparm_query", g_list.getQuery());


        gajax.addParam("sysparm_tableName", g_list.tableName);


        gajax.addParam("sysparm_add_to_table", NOW.task_add_affected.ADD_TO_TABLE);


        gajax.getXMLAnswer(closeWindow);


}



Depending on your goal you could try to work out the addAll function in the script include to be able to use it based on what you want to do. This would be if you would like to use it somewhere else.



If you want to change the behavior of the Add all button, you could try to rebuild the UI page to have a custom one with your custom button. Or you could modify what the addAll function does inside the Script Include by customizing it (you can't extend it or copy it as the call to the function is hard coded in the UI page you can't modify).


Thank you Laurent, that was great detail. I am interested in either:


1. Adding a alert message (Ex: "Are you sure, you want to add 'XX' CIs to Change?") on click of 'Add all' button.


or


2. Get rid of the 'Add all' button from this page.



How do you think it can be achieved? Is this something at cmdb_ci table scope?




Thanks,


Hari


Ok, I had some fun with your requirements.



What I mean by that is that I replaced the client side function addAllToTask() with some a custom function using javascript. However, this is done by manipulating the iframe popup which is really not clean. It also relies on dependencies of the actual code which is subject to change (ex: tabs2_list class as SNOW is currentyle moving to list v3 in Helsinki, however still in Helsinki the list v2 is used for that particular list). However, of my knowledge, I don't know any other clean way to do it beside rebuilding the UI Page by making a custom one.



For the benefit it gives, I'm not even sure I would personnaly put this in Production by fear that the next one after me would have difficult maintenance to do with this modification. However, if that script ever broke you could simply decide to revert the UI Action to it's out of the box state.



So what I proposed if modifying the UI Action https://<instance_name>.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=77688cfe6f35f100e5f2b3312e3ee4e6



Your function openList would become:



function openList(answer){


      var url = answer;


     


      var cmdbciOverlay = new GlideOverlay({


              id : "cm_add_affected_cis",


              title : getMessage("Add Affected Configuration Items"),


              iframe : url,


                      closeOnEscape : true,


              showClose : true,


              onAfterClose: refreshAffectedCIs,


              onAfterLoad: resizeIframe,       //Once PRB632264 is fixed by platform we can comment this line


              height : "90%",


              width : "90%"


      });


     


      cmdbciOverlay.setOnAfterLoad(replaceAddAllFunction); //Setting the On after load again replace the original one set previously


     


      cmdbciOverlay.center();


      cmdbciOverlay.render();


}



Then we define the new function replaceAddAllFunction, you can place this code at the bottom of your script:



function replaceAddAllFunction(){


      //Kepping what the resizeIframe was doing


      var x = g_glideBoxes.cm_add_affected_cis;


      x.autoDimension();


      x.autoPosition();


      x._createIframeShim();


     


      var iframe = document.getElementsByClassName("gb_iframe")[0]; //Get the iframe rendered


      //Replace the iframe addAllToTask function


      iframe.contentWindow.addAllToTask = function(){


             


              var numberOfItems = iframe.contentDocument.getElementsByClassName("tabs2_list")[0].getAttribute("tab_rows_v2"); //Using the list div element to get the number of item retrieving it by it's class name which is unique in the iframe


             


              var conf = confirm("Are you sure, you want to add " + numberOfItems + " CIs to Change?");


             


              if(conf == true){


                      var g_list = iframe.contentWindow.GlideList2.get(iframe.contentWindow.NOW.task_add_affected.TABLE_NAME);


                      var gajax = new GlideAjax("AssociateCIToTask");


                      gajax.addParam("sysparm_name","addAll");


                      gajax.addParam("sysparm_id", iframe.contentWindow.NOW.task_add_affected.TASK_ID);


                      gajax.addParam("sysparm_query", g_list.getQuery());


                      gajax.addParam("sysparm_tableName", g_list.tableName);


                      gajax.addParam("sysparm_add_to_table", iframe.contentWindow.NOW.task_add_affected.ADD_TO_TABLE);


                      gajax.getXMLAnswer(iframe.contentWindow.closeWindow);


              }


              else{


                      //Do nothing, the popup will close itself


              }


      };


}



I only tested this in Chrome Browser and using Helsinki so this hasn't been tested thoroughly. You should probably do so if you chose to put this in Production. If you plan on using this and maintain it or produce documentation for eventual maintenance feel free to ask me question to help you understand what this code does.