Reference field shows value as 'undefined'

AndresGT1
Giga Expert

Hello,

I'm currently working on a 'after- insert' Business Rule that initializes a new record using current values, but some are sending an 'undefined' value even though they are full.

All values being managed are from reference fields

For example we have this two fields in the current form.

- Area Desarrollo (u_area_desarrollo)

- Clasificación del Proyecto (u_clasificacion_del_proyecto)

Now.. after they insert that record the business rule triggers and this is the code

// This is the part of the code where the mistake appears

var gr = new GlideRecord('pm_project');

gr.initialize();

gr.u_area_desarrollo = current.u_area_desarrollo;

gr.u_clasificacion_del_proyecto = current.u_clasificacion_del_proyecto;

gr.insert();

After the Business Rule runs, this is how the new record's form shows. You can see that 'Clasificación del Proyecto' got filled, while 'Area Desarrollo' stayed empty.

When I displayed the values in a string, 'Clasificación del Proyecto' brings the sys_id of the reference (as planned) and 'Area Desarrollo' displays a value of 'undefined'. Why is this happening? Any ideas?

If you need any more information please let me know

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Andres,



Can you replace current.u_area_desarrollo; with current.getValue('u_area_desarrollo'); and check once. Also is there any reference qualifier on the target reference field?


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Andres,



Can you replace current.u_area_desarrollo; with current.getValue('u_area_desarrollo'); and check once. Also is there any reference qualifier on the target reference field?


It worked, thanks a lot!



Would it be too much if I asked you to explain me why?



What's the difference between assigning directly with only current and using current.getValue('x');


Thanks for the update Andres. Output will be object if we fetch the value directly and it will be string if we use current.getValue('fieldname');



I hope this answers your question.