gr[fieldName].getLabel() does not work on sys_email table

xiaix
Tera Guru

As I had originally posted here:   https://community.servicenow.com/thread/216254

I just found out that if I query the sys_email table with a sys_id, the gr[fieldName].getLabel() breaks the script include.

1 ACCEPTED SOLUTION

I figured out what was breaking it.



if (gr.next())


{


      var directURL = (gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=" + tableName + ".do?sys_id=" + sysID);


     


      fields = new GlideRecordUtil().getFields(gr);


      for (var i = 0; i < fields.length; i++)


      {


              fieldName = fields[i];


             


              // WITHOUT THIS IF() STATEMENT,


              // THIS SCRIPT WILL **BREAK** BECAUSE


              // "sys_table_name" IS NOT A FIELD ON THE sys_email TABLE!!


              //


              // IF IT'S NOT ON THE TABLE, WHY THE HECK DOES IT FIND IT!!?????


              if (fieldName == "sys_table_name")


                      continue;


             


              recordArray.push({ field_name: fieldName, value: gr.getDisplayValue(fieldName), url: directURL, label: gr[fieldName].getLabel() });


              fieldsFound = 'true';


      }


     


      if (fieldsFound == 'true')


              return (new JSON().encode(recordArray));


      else


              return "No table fields were found in the GlideRecordUtil().getFields(gr) call";


}



Notice the new if() in my code above.



How the heck does "sys_table_name" get found when it's nowhere on the sys_email table!??


View solution in original post

5 REPLIES 5

I figured out what was breaking it.



if (gr.next())


{


      var directURL = (gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=" + tableName + ".do?sys_id=" + sysID);


     


      fields = new GlideRecordUtil().getFields(gr);


      for (var i = 0; i < fields.length; i++)


      {


              fieldName = fields[i];


             


              // WITHOUT THIS IF() STATEMENT,


              // THIS SCRIPT WILL **BREAK** BECAUSE


              // "sys_table_name" IS NOT A FIELD ON THE sys_email TABLE!!


              //


              // IF IT'S NOT ON THE TABLE, WHY THE HECK DOES IT FIND IT!!?????


              if (fieldName == "sys_table_name")


                      continue;


             


              recordArray.push({ field_name: fieldName, value: gr.getDisplayValue(fieldName), url: directURL, label: gr[fieldName].getLabel() });


              fieldsFound = 'true';


      }


     


      if (fieldsFound == 'true')


              return (new JSON().encode(recordArray));


      else


              return "No table fields were found in the GlideRecordUtil().getFields(gr) call";


}



Notice the new if() in my code above.



How the heck does "sys_table_name" get found when it's nowhere on the sys_email table!??