- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2019 11:53 AM
We have a custom CI table that I want to reference on a form. What I would like to do is limit the choices to only CI items that are not currently related to another asset.
My fuzzy logic is
- Check the relationship table
- If the current CI is listed in that able as a child exclude it from the search results
- If not then show it.
Can this be done since I am checking a different table than the one I am referencing or is there another way to go about it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2019 11:49 PM
Hi Steve,
Your script include should return the sys_ids of the values that need to be shown. So you write a glide record and query and fetch the ones which need to be shown and return that as comma separated.
Here is the sample code of script include which can be used as a reference. This script include accepts a user parameter and return the groups sys_ids on this parameter
var GetCurrentUserGroups = Class.create();
GetCurrentUserGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize:function() {
},
BackfillAssignmentGroup:function(user) {
gs.info("In the log");
var gp = [];
var a = user; // capture the sysID passed to this function
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user',a);
grp.query();
while(grp.next()) {
//build a comma separated string of groups if there is more than one
gp.push(grp.getValue('group'));
}
gs.log(gp);
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp;
},
type: 'GetCurrentUserGroups'
});
You can call the script include the form the reference qualifier like below
javascript:new GetCurrentUserGroups().BackfillAssignmentGroup(current.user);
So your script include need to be updated to accept the parameter like below and call the script include as shown above.
findCmdbRelCpu:function(ci)
Mark the comment as a correct answer and also helpful if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2019 11:49 PM
Hi Steve,
Your script include should return the sys_ids of the values that need to be shown. So you write a glide record and query and fetch the ones which need to be shown and return that as comma separated.
Here is the sample code of script include which can be used as a reference. This script include accepts a user parameter and return the groups sys_ids on this parameter
var GetCurrentUserGroups = Class.create();
GetCurrentUserGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize:function() {
},
BackfillAssignmentGroup:function(user) {
gs.info("In the log");
var gp = [];
var a = user; // capture the sysID passed to this function
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user',a);
grp.query();
while(grp.next()) {
//build a comma separated string of groups if there is more than one
gp.push(grp.getValue('group'));
}
gs.log(gp);
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp;
},
type: 'GetCurrentUserGroups'
});
You can call the script include the form the reference qualifier like below
javascript:new GetCurrentUserGroups().BackfillAssignmentGroup(current.user);
So your script include need to be updated to accept the parameter like below and call the script include as shown above.
findCmdbRelCpu:function(ci)
Mark the comment as a correct answer and also helpful if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2019 07:06 AM
haha it's funny that you posted this because I found this exact script include and was trying on my own last night to do this and I still couldn't get it to work.
I will try again and see if I can do it today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2019 08:26 AM
It took some work on my end but I got it to pull the results correctly. Thanks for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-07-2019 11:59 AM
This helps a lot.
In my case, I was actually looking for groups to where the user didn't belong to, so just in case anybody ever needs it, the only change I did was:
From:
return 'sys_idIN' + gp;
To : return 'sys_idNOT IN' + gp;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2019 07:46 AM
i just had to do something similar.
1) write a script include to grab the data you need
2) you return a string of the format sysidIN + xxxxx
where xxx is a comma separated string of the sysids you want
3) configure the dictionary for the field with the drop down.
select advanced
on the record specification tab referrence qualifier is set to Advanced
the reference qualifier is: javascript: your method
for example: javascript: u_get_my_data()
let me know if you require further assistance.
