I need help on my code i don't know what is wrong

Abigail
Tera Expert

I don't know what is not working on my code.

 

var answer = response.responseXML.documentElement.getAttribute('answer');

The object result is empty and I don't know what is wrong

 

 

Script include

var ApplicationNameFCE = Class.create();
ApplicationNameFCE.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getChoicestype: function () {
		var selectedValue = this.getParameter('sysparm_selected_value');
		var arrayreturn=[];
		arrayreturn = [
			{value: 'access_issues',label: 'Access Issues'},
			{value: 'data_discrepancies',label: 'Data Discrepancies'},
			{value: 'other',label: 'Other'},
			{value: 'security',label: 'Security'}];
			
        if(selectedValue=='enterprise_data_management_edmcs'){
			arrayreturn.push(
				{value: 'chart_of_accounts_mapping',label: 'Chart of Accounts Mapping'},
				{value: 'dff_maintenance',label: 'DFF Maintenance'},
				{value: 'epcm_updates',label: 'EPCM Updates'},
				{value: 'interfaces',label: 'Interfaces'});
		}
		else if(selectedValue.substr(0, 2)=='one'){
			arrayreturn.push(
				{value: 'consolidations',label: 'Consolidations'},
				{value: 'excel_add_in',label: 'Excel Add-in'},
				{value: 'integrations',label: 'Integrations'},
				{value: 'modelling',label: 'Modelling'},
				{value: 'profit_plan_submissions',label: 'Profit Plan Submissions'},
				{value: 'reporting',label: 'Reporting'},
				{value: 'task_manager',label: 'Task Manager'});           
		}
		else if(selectedValue=='fdm'||selectedValue=='fda'||selectedValue=='oracle_cloud'){
			arrayreturn.push(
				{value: 'reporting',label: 'Reporting'});           
        }
		
		return JSON.stringify(arrayreturn);
    },
    type: 'ApplicationNameFCE'
});

 

Catalog Client Script

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

function onChangeApplication() {
    var selectedValue = g_form.getValue('application_name');

    var ga = new GlideAjax('global.ApplicationNameFCE');
    ga.addParam('sysparm_name', 'getChoicestype');
    ga.addParam('sysparm_selected_value', selectedValue);

    ga.getXMLAnswer(populateDropdownVar2);

}


function populateDropdownVar2(response) {

    var answer = response.responseXML.documentElement.getAttribute('answer');

    alert(" answer : " + answer);

    answer = JSON.parse(answer);

    answer.forEach(function(choice) {
        alert('Value: ' + choice.value + ', Label: ' + choice.label);
        g_form.addOption('type_of_issue', choice.value, choice.label);
    });
}

 

 

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @Abigail 

in the client script function populateDropdownVar2() the parameter "reponse" already represents the whole JSON string and thus there is no need to perform any XML operations on it.

Maik

View solution in original post

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Hi @Abigail 

in the client script function populateDropdownVar2() the parameter "reponse" already represents the whole JSON string and thus there is no need to perform any XML operations on it.

Maik

Jayesh Varshney
Tera Expert

Hi @Abigail,

 

Since you are using getXMLAnswer in your client script, there is no need to define the answer variable inside the 

'populateDropdownVar2' function. Since the getXMLAnswer is already returning the answer itself.

You can go through the below link for more clarification.

https://www.servicenow.com/community/developer-articles/getxmlanswer-vs-getxml/ta-p/2307589

 

 

Ankit Kumar6
Tera Contributor

Dear @Abigail 

Since you are using getXMLanswer method here, getXMLanswer only return answer which is far more efficient in client script.In this you no need to parse the object as you directly getting the answer.

so, in your code you no need to use below line.

var answer = response.responseXML.documentElement.getAttribute('answer');

instead in alert pass response in place of answer as shown below:

alert("answer: "+response);

 

Thanks,

Ankit

 

Please mark my answer as correct and helpful if this solves your issue.