- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 09:41 AM
The OOB Dynamic Filter pulls in Parent groups. I inserted new Dynamic Filter Option and the Business Rule that it references. Is there a way to modify the Business Rule so that it doesn't pull in the Parent Groups. Only want the script to pulll in groups that have a "Type" that contains Incident, Task, or Change. All of the parent groups don't have a "Type" value.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 02:17 PM
Sorry Mike just notice you have your getMyAssignments declared on the prototype. You are going to want to move it of the prototype definition so you can call it directly without creating a UserUtil object:
var UserUtil = Class.create();
UserUtil.prototype = {
initialize: function() {
},
type: 'UserUtil'
};
UserUtil.getMyAssignmentGroups = function(userID){
var queryString = "user=" + userID + "^group.typeLIKE52c230cd21412400abe30817dc6fb00f^ORtypeLIKEa59723f0213d6800abe30817dc6fb09d^ORtypeLIKE2da8677721056400abe30817dc6fb0fe";
var groupsArray = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery(queryString);
gr.query();
while (gr.next()) {
groupsArray.push(gr.group.toString());
}
return groupsArray;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 10:15 AM
Hi Mike,
Can you share a screen shot of your filter and business rule; will help to see what you have set up.
Thanks,
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 10:33 AM
Hi Bob,
I copied the OOB Business Rule (groups, banners) and renamed to "assign groups, banners". See Script below
I copied the OOB Dynamic Filter Option (One of My Groups) and renamed to "One of My assignment Groups" See screen shot.
Referenced the new BR in the new Dynamic Filter Option.
Business Rule: assign groups, banner
function getMyAssignmentGroups() {
return gs.getUser().getMyAssignmentGroups();
}
function recurseParents(company, depth) {
if (company) {
if (company.toString().length == 0)
return null;
var temp = new String(company.banner_text.getDisplayValue());
if (temp.length > 0)
return temp;
company = company.parent;
depth++;
if (depth > 10) {
gs.print("Possible recursive company loop with user " + user.name);
return null;
}
return recurseParents(company, depth);
}
return null;
}
function getBannerText() {
var company = user.getCompanyRecord();
var s = null;
var depth = 0;
s = recurseParents(company, depth);
if (s)
return s;
company = getPrimaryCompany();
if (company) {
var s = new String(company.banner_text.getDisplayValue());
if (s.length > 0)
return s;
}
return gs.getProperty("glide.product.description");
}
function recurseImageParents(company, depth, useUI16) {
if (company) {
if (company.toString().length == 0)
return null;
if (useUI16 == "false")
var temp = new String(company.banner_image.getDisplayValue());
else
var temp = new String(company.banner_image_light.getDisplayValue());
if (temp.length > 0)
return temp;
company = company.parent;
depth++;
if (depth > 10) {
gs.print("Possible recursive company loop with user " + user.name);
return null;
}
return recurseImageParents(company, depth);
}
return null;
}
function getBannerSrc() {
var company = user.getCompanyRecord();
var useUI16 = gs.getPreference("use.concourse", "false");
var useUI11 = (gs.getSession().getProperty("device_type")!="doctype");
var logoImage = gs.getProperty("glide.product.image");
var logoImageLight = gs.getProperty("glide.product.image.light");
var s = null;
var depth = 0;
s = recurseImageParents(company, depth, useUI16);
if (s)
return s;
company = getPrimaryCompany();
if (company && useUI16 == "false") {
var s = new String(company.banner_image.getDisplayValue());
if (s.length > 0)
return s;
} else if (company && useUI16 == "true") {
var s = new String(company.banner_image_light.getDisplayValue());
if (s.length > 0 && s!="77eb60325f210100a9ad2572f2b477ae.iix")
return s;
}
if (useUI16 == "true" && !useUI11 && logoImageLight)
return logoImageLight;
else if (useUI16 == "true" && !useUI11 && !logoImageLight && logoImage == "images/logos/logo_service-now.png?v=6")
return "images/logos/logo_service-now_light.png";
else
return logoImage;
}
function getPrimaryCompany() {
var gr = new GlideRecord("core_company");
gr.addQuery("primary", "true");
gr.query();
if (gr.next())
return gr;
return null;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 11:45 AM
Hi Mike,
You are going to have to create your own method for returning user groups that only returns those of the types you want. Then in your BR, you would replace the call to the OOB getMyAssignmentGroups with your custom method call. You can place your custom method in a Script Include that you will call in the BR.
The steps would be:
1. Create a script include called "UserUtil" or something similar
2. Create a method in the SI called UserUtil.getMyAssignmentGroups(userID) - takes in a user ID as a param
3. Define the method querying the sys_user_gr_member table and get the groups for the user where the group types are the only ones you want:
UserUtil.getMyAssignmentGroups = function(userID){
var i = 0;
var queryString = "user=" + userID + "^group.typeLIKE add INT group type value here^ORtypeLIKE add change group type value here^ORtypeLIKE add task group type value here";
var groupsArray = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery(queryString);
gr.query();
while (gr.next()) {
groupsArray.push(gr.group.toString());
}
return groupsArray;
}
Then In your BR change the getMyAssignment groups call to use your new method:
function getMyAssignmentGroupsNoParents() {
var userID = gs.getUser().getID();
return UserUtil.getMyAssignmentGroups(userID);
}
Finally in your dynamic filter, you would change the Script reference to "getMyAssignmentGroupsNoParents()"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 12:56 PM
Thanks Bob!
I modified the BR, Script Include, & changed the Dynamic Filter. I'm still getting Empty value on the filter.
Dynamic Filter
Business Rule:
function getMyAssignmentGroupsNoParents() {
var userID = gs.getUser().getID();
return UserUtil.getMyAssignmentGroups(userID);
}
UserUtil Script Include
var UserUtil = Class.create();
UserUtil.prototype = {
initialize: function() {
},
UserUtil:getMyAssignmentGroups = function(userID){
var i = 0;
var queryString = "user=" + userID + "^group.typeLIKEIncident^ORtypeLIKELocal^ORtypeLIKEChange";
var groupsArray = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery(queryString);
gr.query();
while (gr.next()) {
groupsArray.push(gr.group.toString());
}
return groupsArray;
},
type: 'UserUtil'
};