- 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:46 AM
Nope, you will require a Server Side script can be a BR or a Script Include here so that you can validate that if User is a part of a Group or not.
On Client side I don't think this is possible to validate, you will need a Server script to check.
Display BR is easy and simple to implement rather than a Script include which is not needed here but if you want can be used as well.
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 10:27 AM
Hi
Thank you
I will go with Script Include
Could you please show me how can I use script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 11:06 AM
In that case you need to create a Client callable Script Include and use the script below to check if Logged in User is a Part of the Group you want to check as shown below:
var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroup : function(){
var grp = gs.getUser().isMemberOf('GroupName here');
return grp;
},
type: 'checkGroupMember'
});
Now you need to modify your Client script as well. Please use the script below to validate your requirement:
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");
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
}
This way you can validate based on Script Include and Client Script. If you need to check for multiple group then put an OR condition in your script include.
Again will suggest go with Display BR as Script Include in this case will only increase complexity and maintainability, if this is just for learning purpose then it's okay.
I have shared both ways how you can achieve this.
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 11:21 AM
Hi
Thank you
It is not working
Regards
Shiva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 10:20 PM
Can you share your Script Include and Client script what you have written to assist you further?
I have tested the above code which I Posted and it works for me in my PDI.
Regards,
Shloke
Regards,
Shloke