- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 12:54 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 02:28 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 01:42 AM
you can make it multi line text variable or string variable and show the choices
update script include as this
var TagPop = Class.create();
TagPop.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTagName: function() {
var vendors = [];
var nam = this.getParameter('sysparm_groupid');
var abc = new GlideRecord('label_entry');
abc.addQuery('title', 'CONTAINS', nam);
abc.query();
while(abc.next()) {
vendors.push(abc.label.getDisplayValue());
}
return vendors.toString();
},
type: 'TagPop'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 02:00 AM
Hi Ankur,
Thanks a lot. Its working. But I have a question. Currently all the 3 tags are populating in a single line. I want to show each tag separately. How can I achieve this?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 02:25 AM
Hi,
Please use the steps below to achieve your requirement:
1) Client Callable Script Include and use the script below:
var getTags = Class.create();
getTags.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTagsValue : function(){
var arr= [];
var checkVal = this.getParameter('sysparm_val');
var gr = new GlideRecord('label_entry');
gr.addQuery('table_key',checkVal);
gr.query();
while(gr.next()){
arr.push(gr.label.getDisplayValue().toString());
}
return arr.toString();
},
type: 'getTags'
});
2) On Change Client Script on your Application Field:
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',splitAnswer[i]);
}
}
//Type appropriate comment here, and begin script below
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 02:28 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 02:53 AM
Hi Shloke,
Its working as expected. Thanks a lot!
Thanks!