Show data on a form from another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2022 05:18 AM
I'm trying to pull related data from one table onto the form for another table. I've been reading over previous similar posts but still having trouble. I'm new to scripting so I can't quite interpret what I'm reading to adapt it to my needs. Here's what I'm trying to achieve:
Whenever I create a new hardware model entry into the system, it is assigned a category. On the equipment form, I want to show display that category when the model is selected.
I would really appreciate if someone would break it down for me with some context explanation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2022 09:09 PM
Hi @Jamie Sherry ,
Please write a client script and a script include to achieve this.
The client-side script passes parameters to the Script Include. The Script Include returns data as XML or a JSON object.
Glide Ajax - The GlideAjax class is used by client-side scripts to send data to and receive data from the ServiceNow server.
Please go through the below link for more information on how it works-
https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_le...
Script -
Note - Kindly place the script name , backend value name , function name etc.
On change / On load client script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var xy = g_form.getValue(‘backend name of field’);
var ga = new GlideAjax(‘Scriptt include name’ );
ga.addParam('sysparm_name, ‘function name’); // function name which is defined in script include
ga.addParam('sysparm_backend value of filed’, xy); // value which is stored in variable - xy
ga.getXML(callback);
function callback(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue(‘backend value of field’,answer);
Script Include -
var Script Include Name = Class.create();
Script Include name.prototype = Object.extendsObject(AbstractAjaxProcessor, {
function name: function(){
var am = this.getParameter('sysparm_backend field name’ );// same backend field name which is mentioned in
var getData =new GlideRecord(‘table name’);
getData.addQuery(‘’); //if you want to query any other things from table
getData.query();
if(getData.next()){
return getData.getValue(‘backend field name’); // value which u want to fetch from table
}
},
type: ‘Script Include name’
});
Please mark correct , if it solves your query .
Thank You !
Regards,
Nandini