- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 09:05 AM
Hello
Script for Client script if a user is a part of A assignment group then user can get priority=1 .If user is not part of A assignment group then user should get pop-up for submitting priority=1
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 09:48 AM
Can you put an alert as shown below:
alert(typeof answer);
This will help in debugging what type of value is getting returned whether it is string or boolean and according you can put quotes in If block or not.
Ideally it should be string returned from Script Include and I have tested it and working fine .
Please see screenshot below:
Sharing Script Include and Client Script again for reference:
Script Include:
var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroup : function(){
var grp = gs.getUser().isMemberOf('Analysts');
return grp;
},
type: 'checkGroupMember'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 1) {
var ga = new GlideAjax('checkGroupMember'); // Script Include Name here
ga.addParam('sysparm_name', 'checkGroup'); // Your Function Name here
ga.getXML(valdiatePriority);
}
function valdiatePriority(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(typeof answer);
if (answer == 'false') {
g_form.addErrorMessage('Your Message Here');
g_form.setValue('priority', oldValue); // To revert to Old Value
}
}
//Type appropriate comment here, and begin script below
}
Put alert in different line on client side and see what value is coming and let me know..
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 09:15 AM
Hi,
Please see the steps below to achieve your requirement:
1) Create a Display Business Rule on Incident Table and use the script below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.checkGroup =gs.getUser().isMemberOf('group Name here');
})(current, previous);
Now
write an On Change Client script on Priority field and use the script below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue == 1){
if(g_scratchpad.checkGroup == false){
g_form.addErrorMessage('Your Message Here');
}
}
//Type appropriate comment here, and begin script below
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 09:16 AM
So if User is not a part of the group you are checking then it will throw an error message and you can clear the value of priority field or set it back to it's old value as well.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 09:17 AM
You can use below two lines which ever you want in your client script shown above:
g_form.setValue('priority',oldValue);// To revert to Old Value
g_form.clearValue('priority');// To clear out the value
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 09:24 AM
Hi
Thank you
Is any There any way we can use only client script By not using BR
If any please help me