Client Script (g_form.setDisplay) not working in Agent Workspace

Hyohyeon Kim
Tera Contributor

Hi Experts.

I've launch my Client Script in production, but suddenly it something went wrong.

UI Type: All

Isolate script: True

onChange script:

Script returns response and alert() also working, but g_form.setDisplay() only does not work.

*It works in Platform UI

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var ga = new GlideAjax('GetChoiceValueInCSM');
    ga.addParam('sysparm_name', 'getChoiceByDependentValue');
    ga.addParam('sysparm_element', 'u_third_category');
    ga.addParam('sysparm_dependentvalue', g_form.getValue('subcategory'));
    ga.addParam('sysparm_tablename', 'sn_customerservice_case');
    ga.getXMLAnswer(getChoices);

    function getChoices(response) {
        if (response) {
			g_form.setDisplay('u_third_category', true);
			alert("!!");
        } else {
            g_form.setDisplay('u_third_category', false);
			alert("!!22");
		}
    }
}

I can't even guess the cause. How can I fix it?

 

Regards.

 

1 ACCEPTED SOLUTION

Hyohyeon Kim
Tera Contributor

Dear Respondents

The cause of this issue has been identified.
The problem wasn't the script. The cause was that the Workspace View Rule did not show the field.

Thank you for your cooperation.

View solution in original post

7 REPLIES 7

Kalyani Jangam1
Mega Sage
Mega Sage

Try to use setValue rather than setDisplay

g_form.setValue('u_third_category', true);

 

Hi, @Kalyani Jangam 

Thanks for your reply. but it doesn't work also.

Kalyani Jangam1
Mega Sage
Mega Sage

Hi, You missed one line of Glideajax code, add below line

function getChoices(response)

{

var answer = response.responseXML.documentElement.getAttribute("answer");// This line

 if(answer){
g_form.Value('u_third_category', 'true');

}

else{

g_form.Value('u_third_category','false');

}

}

Please let us know if it helpful or not

Hi @Kalyani Jangam 

 

The code you mentioned is complemented with getXMLAnswer()

And alert() works fine so the GlideAjax code doesn't seem to be a problem.

var answer = response.responseXML.documentElement.getAttribute("answer");// This line

 

Please refer to the following

getXML() vs getXMLAnswer()? which is the best to use? - Now Platform - Question - ServiceNow Communi...