- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 02:15 AM
Hi All,
In a knowledge form, we have a field called "OpCo (List Collector)", If we have selected any value in the OpCo field (ex: FXE,FXO), this should be populated in the prefix of short description field. I have written onload client script, but instead of choice name, the value is populated, can anyone help me on this? see below images for reference.
Onload Client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var list = g_form.getValue('u_opcom').toString();
alert(list);
var array = list.split(',');
for (var i=0; i < array.length; i++) {
g_form.addInfoMessage("This should be the list collector value " + array[i]);
var shortDesc = g_form.getValue('short_description');
g_form.setValue('short_description', array[i].toString() + ' , ' + shortDesc);
}
}
Here 2 and 1 are the choice value of FXE and FXO.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 03:22 AM
Hi @MS17 ,
Create a client callable script include as follows:
var GetKbArticles = Class.create();
GetKbArticles.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getWatchList:function(){
var id = this.getParameter('sysparm_sysID');
var watchlist;
var kb=new GlideRecord('kb_knowledge');
if(kb.get(id.toString())){
watchlist=kb.getDisplayValue('u_opcom');
}
return watchlist.toString();
},
type: 'GetKbArticles'
});
And call in client script.
function onLoad() {
//Type appropriate comment here, and begin script below
if (!g_form.isNewRecord()) {
var arr = [];
var ga = new GlideAjax('GetKbArticles');
ga.addParam('sysparm_name', "getWatchList");
ga.addParam('sysparm_sysID', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer) {
arr = answer.split(',');
for (var i = 0; i < arr.length; i++) {
g_form.addInfoMessage("This should be the list collector value " + arr[i]);
var shortDesc = g_form.getValue('short_description');
g_form.setValue('short_description', arr[i].toString() + ' , ' + shortDesc);
}
});
}
}
Thanks,
Gopi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 07:49 AM
You can use below :
function onLoad() {
var list = g_form.getValue('u_opcom').toString();
var shortDesc = g_form.getValue('short_description').split(':');
if (shortDesc.length > 1)
shortDesc = shortDesc[1];
else
shortDesc = shortDesc[0];
var op = [];
var array = list.split(',');
for (var i = 0; i < array.length; i++) {
if (array[i] == '1')
op.push('FXO');
if (array[i] == '2')
op.push('FXE');
}
if(op.length>0)
g_form.setValue('short_description', op.toString() + ':' + shortDesc); // here : is used to separate OpCo and short description
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 03:34 AM
Hi @Anil Lande,
It is working now! If I have modified the Opco field, it should wipe out the old opco value in short description, it is taking the older value also.
In the below image I have selected FXO,FXE after that I have removed FXE from the field, but it is taking older values also, The short description field should be populated with the value from updated value of OpCo field. Please suggest.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 03:46 AM
I would suggest to use delimiter to separate Short description and OpCo values.
function onLoad() {
//Type appropriate comment here, and begin script below
var list = g_form.getValue('u_opcom').toString();
var shortDesc = g_form.getValue('short_description').split(':');
if(shortDesc.length>1){
shortDesc = shortDesc[1];
alert(list);
var op ='';
var array = list.split(',');
for (var i=0; i < array.length; i++) {
if(array[i]=='1')
op = op+'FXO, ';
if(array[i]=='2')
op = op+'FXE,';
}
g_form.setValue('short_description', op +':'+ shortDesc); // here : is used to separate OpCo and short description
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 03:56 AM
Hi @Anil Lande,
The above script is not working, not populating opco value in short description field.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 04:11 AM
Please try below script:
function onLoad() {
var list = g_form.getValue('u_opcom').toString();
var shortDesc = g_form.getValue('short_description').split(':');
if (shortDesc.length > 1)
shortDesc = shortDesc[1];
else
shortDesc = shortDesc[0];
var op = [];
var array = list.split(',');
for (var i = 0; i < array.length; i++) {
if (array[i] == '1')
op.push('FXO');
if (array[i] == '2')
op.push('FXE');
}
g_form.setValue('short_description', op.toString() + ':' + shortDesc); // here : is used to separate OpCo and short description
}
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 04:56 AM
Hi @MS17 ,
Did you get chance to check update script?
Could you please close this question by marking appropriate response as Helpful and correct solutions.
Thanks
Anil Lande