- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2021 01:50 PM
Hello,
I have a requirement to hide an option in a custom reference field (u_technical_review_group) looking at the sys_user_group table, unless the user has a specific role). I managed to do this through the following script...
javascript:var refQual= new GlideRecord('sys_user_has_role');Ops_RoleGR.addQuery('role', 'c24205a41ba76010c0174199bc4bcb4f');Ops_RoleGR.addQuery('user',gs.getUserID());Ops_RoleGR.query();if(!Ops_RoleGR.next()) {^sys_id!=834e91431b51c850338b6576bc4bcb55'} ;
In addition to this, I also need to only display groups where activeISTRUE and sourceISNOTEMPTY. I've tried adding ^active=true^sourceISNOTEMPTY to the end of the reference qualifier but the query isn't being applied.
I'm guessing this could be a syntax issue but would appreciate some help.
Thanks!
Kevin
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2021 01:57 PM
Hi Kevin,
Its better if you create a script include and define a function in it and call it in ref qual as below.
javascript:new myScriptInclude().myFunction(paramter1,paramter2, etc...)
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2021 01:57 PM
Hi Kevin,
Its better if you create a script include and define a function in it and call it in ref qual as below.
javascript:new myScriptInclude().myFunction(paramter1,paramter2, etc...)
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 06:21 AM
Hi Saurabh,
I've created a script include for the role check and called it in the reference qualifier, but how to add the additional conditions? These conditions are independent of the role check and should be applied to all users. Below is the script include I created for the role check...
var OpsKBCheck = Class.create();
OpsKBCheck.prototype = {
initialize: function() {
var OpsKB = new GlideRecord('sys_user_has_role');
OpsKB.addQuery('role', 'c24205a41ba76010c0174199bc4bcb4f');
OpsKB.addQuery('user',gs.getUserID());
OpsKB.query();
if(!OpsKB.next()){
sys_id!='834e91431b51c850338b6576bc4bcb55';
}
},
type: 'OpsKBCheck'
};
Thank you,
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 06:26 AM
Hi Saurabh,
You can disregard my previous reply. I had to place the additional conditions at the beginning of the reference qualifier prior to the script include and it's working as desired...
active=true^sourceISNOTEMPTY
javascript:OpsKBCheck();^
Thanks for the help!
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2021 01:57 PM
Hi Kevin,
Use script include in advance reference qualifier and write down all required conditions in the script include.
You can see the below example as reference.
https://servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-script-include/
Thanks,
Mihir