How do I auto populate a variable on a Service Catalog Item from another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2021 08:05 AM
Hello Community,
I have a business requirement to add a reference variable to a catalog item called Information System Name which references a table called u_is_number.
There are two fields Business Unit (u_business_unit) and System Type (u_is_type) that need to auto populate based on the Information System Name.
Can someone help with what should be entered in the default values of those two variables?
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2021 08:16 AM
Hi,
So for this you'd want to create those 3 variables if not already.
Then create an onChange client script that is set to execute when the Information System Name field is changed...this script will execute a GlideAjax (script include) which contacts the server to get the related information for those 2 other fields, brings it back to the client, and then fills it automatically in those fields.
Here's a glideajax cheat sheet to help you get started: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...
Please attempt yourself and let us know if you have any other questions.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2021 09:56 AM
Hi,
I just wanted to check-in on this and see how you're doing.
If my reply above helped guide you Correctly, please also mark as Correct.
Thanks and take care! 🙂
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2021 08:17 AM
You can refer this code for default value population which will populate one record.
javascript: getValue(); function getValue(){var gr = new GlideRecord('u_is_number'); gr.query(); if(gr.next()){return gr.sys_id;}}
But I think you should go with Script Include and Client Script
Write OnChange Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('Autopopulate_Catalog');
ga.addParam('sysparm_name','autopopulate');
ga.addParam('Information_System',newValue);
ga.getXML(callBack);
function callBack(response)
{
var answer = response.responseXML.documentElement.getAttribute('answer');
var result = JSON.parse(answer);
g_form.setValue('g_form.u_business_unit',result businessUnit);
g_form.setValue('g_form.u_is_type',result.isType);
}
}
Client Callable Script Include
var Autopopulate_Catalog = Class.create();
Autopopulate_User.prototype = Object.extendsObject(AbstractAjaxProcessor, {
autopopulate: function()
{
var obj = {};
obj.businessUnit='';
obj.isType='';
var gr = new GlideRecord('u_is_number');
if(gr.get(this.getParameter('sysparm_caller')))
{
obj.businessUnit = gr.businessUnit.toString();
obj.isType = gr.isType.toString();
}
return JSON.stringify(obj);
},
type: 'Autopopulate_Catalog'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2021 08:02 AM
Just curious to know if your issue is resolved now.
If yes, can you please mark appropriate response as correct for others who may have a similar question in the future and close this unresolved thread.
If not, please let us know if you need any other help
Thank you