g_form.getReference returns an undefined value

Jon23
Mega Sage

I am currently trying to create a child ticket with all the information from the parent in it.

Using the new button on the related list 'Facilities Request->Parent';

Capture.PNG

the following client script is triggered:

function onLoad() {

    if(g_form.isNewRecord()){

          var dad = g_form.getValue('parent');

          if(dad != ''){

                var parentRecord = g_form.getReference('parent');

                g_form.setValue('opened for', parentRecord.opened_for);

                g_form.setValue('location', parentRecord.location);

      jslog("JW-DEBUG: " + parentRecord.opened_for);

      jslog("JW-DEBUG: " + parentRecord.location);

          }

    }

}

function onLoad() {

    if(g_form.isNewRecord()){

          var dad = g_form.getValue('parent');

          if(dad != ''){

                var parentRecord = g_form.getReference('parent');

                g_form.setValue('opened for', parentRecord.opened_for)

The location field is correctly populated on my child ticket, however, the opened_for is not.

Looking at the javascript log i see the following:

JW-DEBUG: undefined

JW-DEBUG: b466f2800a0a3c7e00b84e0d16c206ae

Both fields are reference fields so I am confused why one works and one does not - any suggestions?

20 REPLIES 20

Thank you derekculbertson for your reply. 

While searching for my requirement, came across this script, which helped me 🙂

Cheers!

Suhas Marathe