- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2017 07:02 PM
Hello my fellow developers!
I have a requirement to filter the list that you get using the Affected CI related list edit button. I have a script include that works perfectly in filtering the list or the slush bucket items when manually entered like you see below. The condition is javascript:GetRelCis('sys_id of a CI') and it basically walks a straight line up and down the relationship tree and returns related objects. (similar to a flattened dependency view).
The problem is that this script takes a CI sys_id as a parameter and I would like the default filter to use the CI sys_id on the incident or change as this parameter.
I can put the script includes call with a hard coded parameter into the Default filter field for the related list and have it work perfectly, but I can't for the life of me figure out how to pass in the sys_id of the current tasks selected CI. I have looked into trying to use an on load client script for this form but again I can't seem to find how to grab the task.cmdb_ci from the originating form. a dynamic filter option is not available on sys_id and I am not sure that would work for this scenario. Please help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2017 01:27 PM
Thank you to everyone that replied. As is often the case there are many ways to accomplish the same goal and while I was able to get a few of these suggestions up and going I ultimately went another direction that I came up with on my own. I am not sure how this will work long term but let me document what I did.
So there is a related list that is on the tasks for Affected CI and you can edit the list control on this related list. In the list controls if you set a default filter then that filter will be applied by default when you hit the edit button. The best thing about this is that you can clear out the filter and get all CI's in the list or provide your own filter. The other great thing is the list controls are in a table sys_ui_list_control.
What I did at first was to create an on display business rule that looked up the appropriate list control and then I could programmitically set the edit_default_filter property and give it the filter that I wanted by forming a string
var rel_list = new GlideRecord('sys_ui_list_control');
rel_list.addQuery('name', current.getTableName()); //Get the related lists controlls for this table
rel_list.addQuery('related_list', 'task_ci.task'); //Get the related list control for this list
rel_list.query();
if(rel_list.next()){
if(current.cmdb_ci == ''){
rel_list.edit_default_filter = '';
rel_list.update();
}
else{
var filter = 'sys_id=javascript:GetRelCis(\"' + current.cmdb_ci.toString() + '\")^sys_class_name=cmdb_ci_service^ORsys_class_name=u_cmdb_service_application^ORsys_class_name=u_cmdb_service_environment^ORsys_class_nameINSTANCEOFcmdb_ci_server';
rel_list.edit_default_filter = filter;
rel_list.update();
}
}
Ultimately I decided that setting the default filter on the list control when the page loaded would likely not be good because who knows how many people are going to be looking at how many incidents at the same time. I moved the code into a script includes and altered the "edit" button UI action to set the filter based on the context when the button is pressed. There is still an opportunity for the filter to be incorrect when the slush bucket opens but the window for the filter to be overwritten is very small.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 02:29 AM
Hi Scott,
Here listing down two community posts that might be helpful to you.
Cannot set default filter on Related List Edit Button
Regards,
Riyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 11:09 AM
Riyanka,
That first link is very useful and I was able to get the filter to work using some of the suggestions in that thread. It is not a perfect solution for my requirement as there is no way for a user to clear the filter in case they need to search for and add a CI that doesn't have a direct relationship.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 05:22 AM
Hi,
I suggest to use an UI Action:
The code in "addCiInMyTask" UI Action can be:
function openCisList(){
var gajax = new GlideAjax("global.AssociateCIToTask"); //AssociateCIToTask is a System Script
gajax.addParam("sysparm_name","getURL");
gajax.addParam("sysparm_id", g_form.getUniqueValue());
gajax.addParam("sysparm_add_to", "task_ci");
gajax.addParam("sysparm_ci_class", "x_xxx_YourCiClass"); //Here you give the class name of your CI or comment it
var filter='u_status=3'; //Here you should give an appropriate filter
gajax.addParam("sysparm_filter", filter);
gajax.getXMLAnswer(openList);
}
function openList(answer){
var cmdbciOverlay = new GlideOverlay({
id : "cm_add_affected_cis",
title : getMessage("Add my CI"),
iframe : url,
closeOnEscape : true,
showClose : true,
onAfterClose: refreshAffectedCIs,
onAfterLoad: resizeIframe,
height : "90%",
width : "90%"
});
cmdbciOverlay.center();
cmdbciOverlay.render();
}
function refreshAffectedCIs() {
var listId = g_form.getTableName() + ".task_ci.task";
var list = typeof GlideList2 !== "undefined" ? GlideList2.getByName(listId) : null;
if (list == null)
list = typeof GlideList !== "undefined" ? GlideList.get(listId) : null;
if (list != null)
list.refresh();
}
function resizeIframe(){
var x = g_glideBoxes.cm_add_affected_cis;
x.autoDimension();
x.autoPosition();
x._createIframeShim();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 11:07 AM
Alireza,
Thank you so much for this input as it may be the solution that I was looking for. Let me play with this and see if I can get it to work and I will let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2017 01:27 PM
Thank you to everyone that replied. As is often the case there are many ways to accomplish the same goal and while I was able to get a few of these suggestions up and going I ultimately went another direction that I came up with on my own. I am not sure how this will work long term but let me document what I did.
So there is a related list that is on the tasks for Affected CI and you can edit the list control on this related list. In the list controls if you set a default filter then that filter will be applied by default when you hit the edit button. The best thing about this is that you can clear out the filter and get all CI's in the list or provide your own filter. The other great thing is the list controls are in a table sys_ui_list_control.
What I did at first was to create an on display business rule that looked up the appropriate list control and then I could programmitically set the edit_default_filter property and give it the filter that I wanted by forming a string
var rel_list = new GlideRecord('sys_ui_list_control');
rel_list.addQuery('name', current.getTableName()); //Get the related lists controlls for this table
rel_list.addQuery('related_list', 'task_ci.task'); //Get the related list control for this list
rel_list.query();
if(rel_list.next()){
if(current.cmdb_ci == ''){
rel_list.edit_default_filter = '';
rel_list.update();
}
else{
var filter = 'sys_id=javascript:GetRelCis(\"' + current.cmdb_ci.toString() + '\")^sys_class_name=cmdb_ci_service^ORsys_class_name=u_cmdb_service_application^ORsys_class_name=u_cmdb_service_environment^ORsys_class_nameINSTANCEOFcmdb_ci_server';
rel_list.edit_default_filter = filter;
rel_list.update();
}
}
Ultimately I decided that setting the default filter on the list control when the page loaded would likely not be good because who knows how many people are going to be looking at how many incidents at the same time. I moved the code into a script includes and altered the "edit" button UI action to set the filter based on the context when the button is pressed. There is still an opportunity for the filter to be incorrect when the slush bucket opens but the window for the filter to be overwritten is very small.