- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 04:13 AM
Hello All and @Ankur Bawiskar ,
Can anyone please help us on the below issue.
We opened one catalog item on portal level and "Requested for" variable is auto populated,
And when we clear the "Requested for" variable to select other users then the next minute, we're getting the below error on Top.
Error: undefined- does not have an employee number in the system. Please enter one manually.
Note: We're currently in Utah version and "Requested for" variable is in one variable set and all the used catalog items level we're getting the same error.
Thanks,
LARA
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 04:44 AM
your client script is missing the code not to do the validation if value is empty, may be try putting below code after first line
if(newValue == ''){
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 05:00 AM
update as this
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == '')
return;
if(oldValue != newValue)
var usrEmp = g_form.getReference('u_requestedFor', getEmpNum);
function getEmpNum(usrEmp) {
if (usrEmp.employee_number == undefined) {
var a = g_form.getUniqueValue();
if (a != '6d914f3e1bdef300997ebb7acd4bcbb9') {
g_form.addErrorMessage(usrEmp.name + '- does not have an employee number in the system. Please enter one manually.');
}
g_form.setValue('catItemDef_employeeNumber', '');
} else {
g_form.setValue('catItemDef_employeeNumber', usrEmp.employee_number);
g_form.setReadOnly('catItemDef_employeeNumber', true);
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 05:06 AM
Hi @LaraReddy ,
I noticed that when you clear the "Requested For" field, the script is not able to retrieve the reference record. I suggest trying the following code, which clears the employee number when "Requested For" is empty, which should be the ideal case:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.clearValue('catItemDef_employeeNumber');
return;
}
var usrEmp = g_form.getReference('u_requestedFor', getEmpNum);
function getEmpNum(usrEmp) {
if (usrEmp.employee_number == undefined) {
var a = g_form.getUniqueValue();
if (a != '6d914f3e1bdef300997ebb7acd4bcbb9') {
g_form.addErrorMessage(usrEmp.name + '- does not have an employee number in the system. Please enter one manually.');
}
g_form.setValue('catItemDef_employeeNumber', '');
} else {
g_form.setValue('catItemDef_employeeNumber', usrEmp.employee_number);
g_form.setReadOnly('catItemDef_employeeNumber', true);
}
}
}
Please let me know if this works for you and mark helpful if its worked.