we have written a code when the user has cost center and manager and location should auto populate this is working fine, but for the cost center it is referring to the person department f the user has department then it should get populate on onload and on change if the person doesn't have any department then a (please_mention_cost_center) this variable should be visible and mandatory here everything works fine for admin roles but when I impersonate as end user the error saying( Error There is a JavaScript error in your browser console) showing this and console message is showing as below. can someone please help me to overcome this issue.
Here below the validation was not working eve though i have changed the user for onchange and as well for onloading of the form.
This is my on change client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('LRQA_fetchlocation_details');
ga.addParam('sysparm_name', 'getLocationDetails');
ga.addParam('sysparm_userSysId', g_form.getValue('requested_for'));
ga.getXML(getEmailcallBack);
function getEmailcallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('requestor_s_manager', result.manager);
g_form.setValue('cost_centre', result.department);
g_form.setValue('location', result.location);
// Check if the cost center field is empty
if (!result.department || isLoading) {
// Making the new variable mandatory and visible
g_form.setMandatory('please_mention_cost_center', true);
g_form.setDisplay('please_mention_cost_center', true);
g_form.setReadOnly('cost_centre', true);
// Adding an alert or a message to notify the user
g_form.addInfoMessage('Please fill in the required fields.');
} else{
// Making the new variable not mandatory and not visible
g_form.setMandatory('please_mention_cost_center', false);
g_form.setDisplay('please_mention_cost_center', false);
g_form.setReadOnly('cost_centre', false);
}
}
}
this is my onload client script that it should get works on onloading the form as well. i'm using the onload script not only for the onloading of the form but also it should get applicable for the RITM and sc task level
function onLoad() {
fetchLocationDetails();
function fetchLocationDetails() {
var ga = new GlideAjax('LRQA_fetchlocation_details');
ga.addParam('sysparm_name', 'getLocationDetails');
ga.addParam('sysparm_userSysId', g_form.getValue('requested_for'));
ga.getXML(getEmailcallBack);
}
function getEmailcallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('requestor_s_manager', result.manager);
g_form.setValue('cost_centre', result.department);
g_form.setValue('location', result.location);
if (!result.department) {
// Making the new variable mandatory and visible
g_form.setMandatory('please_mention_cost_center', true);
g_form.setDisplay('please_mention_cost_center', true);
g_form.setReadOnly('cost_centre', true);
// Adding an alert or a message to notify the user
//g_form.addInfoMessage('Please fill in the required fields.');
} else {
// Making the new variable not mandatory and not visible
g_form.setMandatory('please_mention_cost_center', false);
g_form.setDisplay('please_mention_cost_center', false);
//g_form.setReadOnly('cost_centre', false);
}
}
}