The CreatorCon Call for Content is officially open! Get started here.

Write a code for server script for fetching a custom table value ?

1dusjhyahnt
Tera Contributor

Screenshot 2024-02-05 at 10.41.50 AM.jpegScreenshot 2024-02-05 at 1.05.00 PM.jpegScreenshot 2024-02-05 at 10.36.03 AM.jpeg

16 REPLIES 16

Hi @1dusjhyahnt 

 

try this :

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */

      /*1. Declare the array*/
var myArray =[];
/*2. Glide record on table*/
var grInc = new GlideRecord('u_artificatory');
grInc.addQuery('sys_id','458688b893c04210e4f0398efaba10e7');
grInc.query();

if(grInc.next()){
/*2.1 Create empty object*/
var myObject = {

};
               /*2.2 Set object values*/
myObject.name = grInc.getValue('u_name');   //updated 
myObject.class = grInc.getValue('u_class');   //updated
/*2.3 Push object in array*/
myArray.push(myObject);
}
/*3. Set array to data */
data.values = myArray;
   
      gs.addInfoMessage(data.values[0].name);  //updated
gs.addInfoMessage(data.values[0].class);  //updated

})();

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

hi @Vishal Birajdar 

 

not getting any value 

hmm...strange...

May be because of 'class' identifier

 

try this....

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */

      /*1. Declare the array*/
var myArray =[];
/*2. Glide record on table*/
var grInc = new GlideRecord('u_artificatory');
grInc.addQuery('sys_id','458688b893c04210e4f0398efaba10e7');
grInc.query();

if(grInc.next()){
/*2.1 Create empty object*/
var myObject = {

};
               /*2.2 Set object values*/
myObject.name = grInc.getValue('u_name');   
myObject.class_name = grInc.getValue('u_class');   //updated
/*2.3 Push object in array*/
myArray.push(myObject);
}
/*3. Set array to data */
data.values = myArray;
   
      gs.addInfoMessage(data.values[0].name);  
gs.addInfoMessage(data.values[0].class_name);  
})();

 

 

 

If this is not working then check in background script once...

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

now working

Cool....!!!

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates