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

litchick10
Tera Guru

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);
    }
}

 

 

 

 

13 REPLIES 13

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. 

@litchick10 

 

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?

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);

Hitoshi Ozawa
Giga Sage
Giga Sage

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) {

litchick10
Tera Guru

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.