- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 01:29 AM
I need to set value to the field 'u_reserved_by'. Please help me how to get field value instead of sys_id for the below highlighted statement.
function onSubmit() {
g_form.setValue('approval', "Approved");
g_form.setValue('u_status', "Reserved");
var seatGR = new GlideRecord("u_all_seats");
seatGR.addQuery("sys_id", g_form.getValue('u_seat_number'));
seatGR.query();
while(seatGR.next())
{
seatGR.u_availability = "Reserved";
seatGR.u_reserved_by = g_form.getValue('u_name');
seatGR.update();
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 02:02 AM
You can use g_form.getDisplayValue('field name') or g_form.getDisplayBox('field name').value; to get the value of the field.
I prefer using g_form.getReference() method.
Kindly refer to the below code:
function onLoad() {
var b= g_form.getReference('requested_by',fan);
}
function fan(b)
{
var name=b.user_name;
alert(name);
}
the name captures the value of the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 01:33 AM
try u_reserved_by.user_name if the u_reserved_by is sys_user.
Else you will need to set the First Name and the Last Name of your Reserved By. The full Name value on ServiceNow is generated from those two fields and cannot be edited directly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:10 AM
u_reserved_by is String type.
I tried g_form.getDisplayBox('field name').value mentioned by Swati/ Harish and it worked.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 01:53 AM
hi
g_form.getUniqueValue ()will return the sys_id and g_form.getValue('u_name') will return the field value.If it is a referenced field then write g_form.getDisplayValue('u_name');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 02:02 AM
You can use g_form.getDisplayValue('field name') or g_form.getDisplayBox('field name').value; to get the value of the field.
I prefer using g_form.getReference() method.
Kindly refer to the below code:
function onLoad() {
var b= g_form.getReference('requested_by',fan);
}
function fan(b)
{
var name=b.user_name;
alert(name);
}
the name captures the value of the field