need to make variable mandatory and visible for specific group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:20 AM
Can anyone please help me on the below requirement. Need to make one variable visible when the logged in user is member of specific group and need to make mandatory if the variable request type is assign or delete.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:44 PM
Hi,
why you deleted the comment
If you the post or comments for our efforts are useless.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 10:08 PM
Hi,
I have not deleted any comments. Every comment is here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 12:31 AM
Hi,
Okay. No issues. Please check my solution and let me know if you need anything.
If it resolve your issue close the thread by Mark ✅ Correct.
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:21 PM
Hi,
create client and script include using GlideAjax you can get it.
Script Include: create script include and check client callable is true.
var Fetchusergroupinfo = Class.create();
Fetchusergroupinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getData: function() {
var grusr = new GlideRecord('sys_user_grmember');
grusr.addQuery('group', '8a4dde73c6112278017a6a4baf547aa7'); //sysid of your group
grusr.addQuery('user', gs.getUserID()); //it will check with logged in user
grusr.query();
if (grusr.hasNext()) { //if it is part of group it will return true and we can pass it to client script.
return true;
}
},
type: 'Fetchusergroupinfo'
});
Client Script: Create onload catalog client script.
function onLoad() {
var req = g_form.getValue('reuqest_type');
var gausr = new GlideAjax('Fetchusergroupinfo');
gausr.addParam('sysparm_name', 'getData');
gausr.getXMLAnswer(setDetails);
function setDetails(response) {
if (response == true) {
if (req == 'delete' || 'assign') { // add backend values I am assuming those are delete and assign
g_form.setMandatory('fieldname', true); //add your field that you need to make mandatory
} else {
g_form.setVisible('fieldname', true); //show field when user is part of group and request type is not delete and assign
}
}
}
}
Hope it helps!
Please Mark ✅ Correct if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:28 PM
Hello Pritimayee,
You can create a onLoad client script as shown below:
var requestType = g_form.getValue('request_type')
if (requestType == "assign" || requestType == "delete") {
var ga = new GlideAjax("EscalatedScTask");
ga.addParam("sysparm_name", "checkIfGroupMember");
ga.addParam("sysparm_group_name", "YOUR GROUP NAME");
ga.getXMLAnswer(parseReturnedResponse);
}
function parseReturnedResponse(response) {
var isMember = response;
if(isMember) {
g_form.setDisplay("YOUR_FIELD_NAME", true);
g_form.setMandatory("YOUR_FIELD_NAME", true);
}
Create a scritp include where client callable is set to true and use the below code:
checkIfGroupMember: function () {
var groupName = this.getParameter("sysparm_group_name");
return gs.getUser().isMemberOf(groupName);
}
Please mark my respsone as correct/helpful, if it answer your question.
Thanks