- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2018 11:44 AM
All,
I created a display business rule to capture the logged in users role and hide Manager form section tab. Then created an onLoad Client Script to trigger the g_scratchpad variable and if true display the form section tabs else hide. This is all being done on the task table so that it can be used on Incident, Problem, Change. It all seems to work, but i guess not if the tabs don't display when testing with Service Manager role
Display BR
g_scratchpad.user = gs.getUser().hasRole('cde965c0dba96b00145b3a8c7c96199d'); //sys_id of the Role and I have tried it with g_scratchpad.user = gs.getUser().hasRole('Service Manager');
onLoad Client script:
if(g_form.getTableName() == 'incident' || g_form.getTableName() == 'change_request' || g_form.getTableName() == 'problem') {
if (g_scratchpad.user == 'true'){
//execute code
//var sections = g_form.getSectionNames();
g_form.setSectionDisplay('problem_manager',true);
g_form.setSectionDisplay('incident_manager',true);
g_form.setSectionDisplay('change_manager',true);
}
else{
g_form.setSectionDisplay('problem_manager',false);
g_form.setSectionDisplay('incident_manager',false);
g_form.setSectionDisplay('change_manager',false);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2018 12:56 PM
Actually, you should be able to use:
if (g_user.hasRole('Service_Manager')) {
//your code here
}
...directly in your Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 09:55 AM
I updated the display BR with your suggestion above and nothing. I changed the scratchpad variable name to be descriptive as well.
The client script is finding table that I am on, but then nothing inside the if (g_scratchpad.uisservicemanageruser == 'true'){
to display the hidden Manager tab for incident table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 10:50 AM
Already hours and hours trying to solve the same problem. I'm trying catch User domain in display Business Rule , set it to the g_scratchpad.domain variable and pass domain value to the Client Script. Tried everything possible. Its not working. Actually, its not catching even user and domain info in Business Rules using gs.getUser() or gs. getDomainID(). Completely confused. Will be glad to read solution of this problem in this tread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 11:49 AM
Yeah, this is really weird, due to me seeing this a lot in the community forms.
I went ahead and added my logic directly into the client script and it worked.
if (g_user.hasRole('name of or_or domain'))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 02:57 PM
Thank you, Brett for sharing info and very glad you found the solution. I'll try your easy approach next time. We were able set g_scratchpad.domain to true or false using the code below (if someone else will need). Still not clear, why didn't work just gs.getUser() or gs.getDomainID() or current while ServiceNow says should work, but the code below is working to use g_scratchpad.domain in Client Script. Again, thanks and have a great weekend :))
// "Domain Name" - domain name you are looking for
var domainId = gs.getUser().getDomainID();
var domain = new GlideRecord("domain");
domain.addQuery("sys_id", domainId);
domain.queryNoDomain();
if (domain.next()) {
if (domain.name == "Domain Name" || isInParentDomain(domain))
g_scratchpad.domain = true;
else
g_scratchpad.domain = false;
} else
g_scratchpad.domain = false;
function isInParentDomain(domainGr) {
if (domainGr.parent.nil())
return false;
if (domainGr.parent.name == "Domain Name")
return true;
else
return isInParentDomain(domainGr.parent);
}