How to pass an array of values from Script Include to Catalog Client Script?

User205031
Tera Contributor

Hi All,

We have a requirement. If a user selects an Application from 'app_service' then tags related to that application will populate in a different field. So, if an application has 3 tags, how to populate those 3 tags? If an application has 1 tag, it is populating fine but problem is with more than 1 tag. 

 

Catalog Client Script:

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

//Type appropriate comment here, and begin script below

var a = g_form.getValue('app_service');
alert(a);

var ga = new GlideAjax("TagPop");
ga.addParam("sysparm_name", "getTagName");
ga.addParam("sysparm_groupid", a);
ga.getXML(setTagName);

function setTagName(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.clearValue('subscription_name');
g_form.clearOptions('subscription_name');


alert(answer);

g_form.setValue('subscription_name', answer);
}
}

 

Script Include:

var TagPop = Class.create();
TagPop.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getTagName: function() {
var efg = '';
var nam = this.getParameter('sysparm_groupid');
//gs.log('h1' + nam);
//var t = nam.getDisplayValue();
//gs.log('h2' + t);
var abc = new GlideRecord('label_entry');
abc.addQuery('title', 'CONTAINS', nam);
//var vendors = [];
abc.query();
if (abc.next()) {
efg = abc.label.getDisplayValue();
//vendors.push(efg.getUniqueValue());
}
return efg;
//return 'sys_idIN'+vendors.toString();
},

type: 'TagPop'

});

 

Please help!

1 ACCEPTED SOLUTION

Updated CLient Script code to be used here as below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue) {
        var ga = new GlideAjax('getTags');
        ga.addParam('sysparm_name', 'getTagsValue');
        ga.addParam('sysparm_val', newValue);
        ga.getXML(getTags);
    }

    function getTags(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
		var splitAnswer = answer.split(',');
		for(var i=0;i<splitAnswer.length;i++){
			g_form.setValue('description',g_form.getValue('description') + '\n' + splitAnswer[i]);
		}

    }


    //Type appropriate comment here, and begin script below

}

 

This will ensure that tags appear in different lines as you said, did not read it initially but have modified it. Let me know for an issue here.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

15 REPLIES 15

Stefan O1
Tera Contributor

In the catalog client script in Patryk's example use

var answer = JSON.parse(answer);

var tagPop = answer.split(',');