- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2021 11:10 PM
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?
Please help!
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 01:55 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2021 10:21 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2021 10:37 PM
Glad to help.
Please mark appropriate response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2021 12:53 AM
Hi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2021 01:51 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader