Catalog client script error message and error message not showing up in the order guide

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 11:48 AM - edited 11-13-2024 09:31 AM
We have a situation where some users do not have managers, but we require manager approval for a request. I created a client script that populates the requested for email and validates if the user has a manager. If no manager, it clears the requested for value and displays an error message. This error message works in a standard catalog item but not the order guide. All other parts of the script work in both. Any help you can provide would be greatly appreciated:
function onChange(control, oldValue, newValue, isLoading) {
g_form.clearMessages();
var user = g_form.getValue('requested_for');
var gr = new GlideAjax('getTableDataUtils');
gr.addParam('sysparm_name', 'getList');
gr.addParam('sysparm_query_table', 'sys_user');
gr.addParam('sysparm_query_fields', 'email,manager,name');
gr.addParam('sysparm_query_encodedQuery', "sys_idIN" + user);
gr.addParam('sysparm_query_order', 'sys_id');
gr.getXML(populateEmail);
function populateEmail(response) {
var emails = [];
var manager = [];
var uName = [];
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.replace(/},{/g, '}},{{');
answer = answer.replace(/@app./g, "@");
var answerArr = answer.split('},{');
for (var i = 0; i < answerArr.length; i++) {
var answerObj = JSON.parse(answerArr[i]);
emails.push(answerObj.email.toString());
manager.push(answerObj.manager.toString());
uName.push(answerObj.name.toString());
}
if (manager == '') {
var message = uName + ' does not have a manager, Only users with managers can submit this request. Please select a different user';
g_form.addErrorMessage(message);
g_form.clearValue('requested_for');
}
g_form.setValue('requested_for_email', emails);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 09:32 AM - edited 11-13-2024 09:35 AM
Applies on catalog item is checked and if I uncheck it, no part of the code works in the order guide. With it checked everything except the message works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 09:52 AM
It's a strange issue. Can you place a few system logs before and after the message and make sure it's not throwing any run time error?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 11:46 AM
We just did a clone down so I don't have the code to run logs but I sincerely doubt it will give any info since it works in the catalog correctly. I was able to work around by using alert(message); instead of g_form.addErrorMessage(message);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 03:11 PM
Hi @litchick10 You've declared variable "manager" to be an array but checking if it is empty using "manager == ''".
Shouldn't this be as below?
if (manager.length < 1) {

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 03:12 PM
That part actually works, it is only the message that doesn't work and only in the order guide. The message works in standard catalog item.