- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:44 AM
Hi i need to copy field display value of a reference field parent_incident to u_parent_incident(String field).
Kindly check the script which doesnt work and suggest
function onLoad() {
var tes = g_form.getValue('parent_incident') ; //reference field
var test2=g_form.getValue('u_parent_incident'); //
if(test2== '' )
{
g_form.setDisplayValue('u_parent_incident',tes.number);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:49 AM
Hi Param,
That won't work. you need to use getReference with callback as recommended
function onLoad() {
var incident = g_form.getReference(‘parent_incident’, myCallbackFunction);
}
function myCallbackFunction(incident){
g_form.setValue('u_parent_incident', incident.number);
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:49 AM
Hi Param,
That won't work. you need to use getReference with callback as recommended
function onLoad() {
var incident = g_form.getReference(‘parent_incident’, myCallbackFunction);
}
function myCallbackFunction(incident){
g_form.setValue('u_parent_incident', incident.number);
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:49 AM
Hi,
You can not do dot walk like tes.number at the client side. For this either you can refer getReference method or go for GlidaAjax. Check this out for your script reference:
https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_GlideFormGetReference_String_Function
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:49 AM
var tes = g_form.getDisplayValue('parent_incident') and g_form.setValue('u_parent_incident',tes);
it will work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 04:11 AM
function onLoad() {
//var tes = g_form.getDisplayValue('parent_incident') ; //reference field
var tes = g_form.getDisplayBox('parent_incident').value;
//alert(tes);
var test2=g_form.getValue('u_parent_incident'); //
if(test2== ' ' )
{
g_form.setDisplayValue('u_parent_incident',tes);
}
}
When you use g_form.getValue for reference fields, it will provide a sys_id of the record.
You can use g_form.getDisplayValue('fieldname').value function or else use scratchpad(using display business rule).
Thanks,
Shalaka