- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-09-2020 01:55 AM
g_form is used very heavily all over in ServiceNow. Though, it has a lot of documented and undocumented functions/methods. One of the undocumented GlideForm Method is "g_form.resolveNameMap"
#g_form.resolveNameMap:
1. Returns array of object
2. The Object contains the information about the variable like label, Name of the variable, sys_id of the question available for a variable
3. ServiceNow may change their Element ID naming convention in the future and this does not work on Service Portal/Mobile.
4. The resolveNameMap function compares the name of a variable against g_form's nameMap property.
5. nameMap have following information available about the catalog item's variables:
[
{
"prettyName": "requested_by",
"realName": "IO:58f54f302f8a4010dabd59a72799b63f",
"label": "Requested By",
"questionID": "58f54f302f8a4010dabd59a72799b63f"
},
]
Here, In above example:
prettyName: is a variable name. ‘requested_by’ is a variable name.
realName : is sys_id of variable response record in the sc_item_option table. IO:58f54f302f8a4010dabd59a72799b63f is the sys_id of the variable.
label: is a display name or the question of the variable. "Requested By" is the label
questionID: is sys_id of variable / Question.
Example: Let’s say, have below variables on catalog item form.
So, using above mentioned methods we can fetch out the details as below
[ {
"prettyName": "requested_by",
"realName": "IO:58f54f302f8a4010dabd59a72799b63f",
"label": "Requested By",
"questionID": "58f54f302f8a4010dabd59a72799b63f"
},
{
"prettyName": "first_name",
"realName": "IO:39ee3eb21b633300364d32a3cc4bcbe8",
"label": "First Name",
"questionID": "39ee3eb21b633300364d32a3cc4bcbe8"
},
{
"prettyName": "last_name",
"realName": "IO:fd0fbeb21b633300364d32a3cc4bcb8c",
"label": "Last Name",
"questionID": "fd0fbeb21b633300364d32a3cc4bcb8c"
},
{
"prettyName": "email",
"realName": "IO:bf2f32f21b633300364d32a3cc4bcbd6",
"label": "Email",
"questionID": "bf2f32f21b633300364d32a3cc4bcbd6"
},
{
"prettyName": "reporting_manager",
"realName": "IO:49600ff21b633300364d32a3cc4bcbb7",
"label": "Reporting Manager",
"questionID": "49600ff21b633300364d32a3cc4bcbb7"
},
{
"prettyName": "user_role",
"realName": "IO:8f5e6b421b800010364d32a3cc4bcbf2",
"label": "User Role",
"questionID": "8f5e6b421b800010364d32a3cc4bcbf2"
}]
Here Is the client script code to pull the above contents
var x = 0;
var val = '';
var str = JSON.stringify(g_form.nameMap);
g_form.addInfoMessage('The object ' + str);
for (x = 0; x < g_form.nameMap.length; x++) {
// alert(g_form.nameMap[x].toString());
var prettyName = g_form.nameMap[x].prettyName;
var realName = g_form.nameMap[x].realName;
var label = g_form.nameMap[x].label;
var questionID = g_form.nameMap[x].questionID;
g_form.addInfoMessage('prettyName:'+prettyName+": realName :"+realName+": label : "+label+": questionID :"+questionID);
}
Example Use Case :
Most ServiceNow developers will run an AJAX server-side call to the database to fetch a Display Value of a Reference field. But using this method we can get the display value of Reference variable in the Service Catalog.
var varDisp = g_form.getDisplayBox(g_form.resolveNameMap(“variable_name”)).value;
alert(varDisp);
There are some undocumented methods available such as
g_form.mandatoryCheck()
g_form.getMissingFields()
g_form.getEditableFields()
g_form.getDisplayBox(‘field_name’).value
You will find information about these about these methods on below link -
Useful GlideForm Client-side API Methods
Hope you will find it helpful as well. Don’t forget to Mark it Helpful and Bookmark.
Thanks,
Abhishek Gardade
- 2,625 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
too bad this isn't available on portal!