- 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 10:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 04:03 AM
Sure. No Change in Script Include needed(Just make sure CLient Callable is checked) as shown below.
Please use the modified Client Script below:
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(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
}
I Have tested this and is working correctly. Let me know if you stillf ace an issue:
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-12-2022 05:05 AM
Hi
thank you
alert is working fine
it is not going to if condition
Regards
Shiva
- 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