Question on Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I wrote a script include in Employee center core and a client script in the same application for a record producer.
There I have a requirement to check if Requested for is a member of HR groups or not.
I created a field and marking it based on the script include and client script
Client script
Script include:
ANy suggestions what I am missing?
it works but also gives an error of "ErrorThere is a JavaScript error in your browser console"
Any help is highly appreciated.
Thank yoU!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashutoshpat
Can you try this. Slightly modified your code.
If any error throws, please share the error from browser console.
function onChange(control, oldValue, newValue, isLoading)
{
if (isLoading || newValue === '')
{
g_form.setValue('requested_for_is_member_of_hrops', 'false');
return;
}
// If requested_for is cleared
//if (!newValue) {
//g_form.setValue('requested_for_is_member_of_hrops', 'false');
//return;
//}
var hrOpsGroup = 'de66fff31b263614454e0ed3604bcbfb';
var ga = new GlideAjax('CheckGroupMembership');
ga.addParam('sysparm_name', 'isUserInGroup');
ga.addParam('sysparm_user', newValue);
ga.addParam('sysparm_group', hrOpsGroup);
ga.getXMLAnswer(function(answer){
// Optional debug
alert('HR Ops Member: ' + answer);
if (answer === 'true') {
g_form.setValue('requested_for_is_member_of_hrops', 'true');
} else {
g_form.setValue('requested_for_is_member_of_hrops', 'false');
}
});
}
Script include:
var CheckGroupMembership = Class.create();
CheckGroupMembership.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
isUserInGroup: function() {
var userId = this.getParameter('sysparm_user');
var groupId = this.getParameter('sysparm_group');
//if (!userId || !groupId) //at client end validation done for user id
//return 'false';
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group', groupId);
gr.query();
if (gr.hasNext()) {
return 'true';
}
return 'false';
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashutoshpat ,
Can you try commenting the alert in your client script & then try once to see whether u still receive the Java Script error on ur browser.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Tried , no luck
