Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Question on Script include

ashutoshpat
Tera Contributor

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 

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading)
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) {

if (answer === 'true') {
g_form.setValue('requested_for_is_member_of_hrops', 'true');
} else {
g_form.setValue('requested_for_is_member_of_hrops', 'false');
}

// Optional debug
alert('HR Ops Member: ' + answer);
});
}

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)
return 'false';

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group', groupId);
gr.query();

return gr.hasNext().toString();
}

});

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!
14 REPLIES 14

Rafael Batistot
Kilo Patron

Hi @ashutoshpat 

 

May you confirm these steps:

 

  • Script Include must be client callable
  • Do not use global.AbstractAjaxProcessor in scoped Employee Center apps
  • alert() causes browser console errors in Service Portal
If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

Yes 

 

So what should be done for employee center cases?

 

yashkamde
Mega Sage

Hello @ashutoshpat ,

 

Plz check the browser console to get describe what's the actual error.

"There is a JavaScript error in your browser console" error message appears when accessing the Servi... 

If my response helped mark as helpful and accept the solution.