Displaying a Field Value

MuhammadAqS
Tera Contributor

Hi,

I have retrieved a table value, and want to display it on the form using Glide Ajax. The value is retrieving correctly from the table, but is not displaying on the form. I have performed the debugging, and the found that value has retrieved successfully from the table.

In the attached picture, you can see that the value of the Directorate field is not displaying in the field. I want to display the value in the field.


Kind Regards,
Aqil Sajjad

MuhammadAqS_0-1733133323386.png

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@MuhammadAqS Directorate is a reference field and accepts a sys_id (32 character unique identifier e.g. 965a1dd847d21654a6124bad436d43db )as value instead of a string value like Technology. You need to set the sys_id of Technology record in place of string "Technology" as value. Once done value will start reflecting correctly.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@MuhammadAqS Directorate is a reference field and accepts a sys_id (32 character unique identifier e.g. 965a1dd847d21654a6124bad436d43db )as value instead of a string value like Technology. You need to set the sys_id of Technology record in place of string "Technology" as value. Once done value will start reflecting correctly.

Hi @Sandeep Rajput,
I would greatly appreciate your assistance in identifying the specific changes needed in the following code to resolve the issue

Script Include:

getUserDataById: function(userId) {

      var userRecord = {};

      var userGr = new GlideRecord('sys_user');

      if (userGr.get(userId)) {

         userRecord = {

            sys_id: userGr.getValue('sys_id'),

             operatingdivision: userGr.getValue('u_operating_division'),       

         };

      }

      return userRecord;

   },

   

   process: function() {

      var userId = this.getParameter('sysparm_user_id');

      var result = this.getUserDataById(userId);

      return new JSON().encode(result);

   }

});


Client Script:

function onLoad() {
   //Type appropriate comment here, and begin script below
   var userId = g_form.getValue('opened_for');
   getUserDataById(userId, function(userData) {

    //alert(userData.operatingdivision);
   
    g_form.setValue('line_manager', userData.linemanager);
    g_form.setValue('location', userData.worklocation);
    g_form.setValue('directorate',userData.operatingdivision);
   
   });
function getUserDataById(userId, callback) {
   var ga = new GlideAjax('global.UserQueryScriptInclude');
   ga.addParam('sysparm_name', 'process');
   ga.addParam('sysparm_user_id', userId);
   ga.getXML(function(response) {
      var data = response.responseXML.documentElement.getAttribute('answer');
      var userData = JSON.parse(data);
      callback(userData);
   });
}
}




Runjay Patel
Giga Sage

Hi @MuhammadAqS ,

 

I icon indicating that filed have value but as it is a reference field so may display filed value for this record have empty, hence it is not showing here. Open that record and update the display value , it will start appearing on your field.