Setting the default value of a reference field

CharlesR1
Kilo Guru

Hello all,

Hopefully a quick one. On our Purchase Order Line Item table, we need to set the default value on the Vendor field to be the same as the Vendor field on the parent Purchase Order. Both fields are references to the same 'Company' table, but we can't seem to get the selected vendor on the PO record to appear when a new line item is opened.

In the Default value section, we are using 'javascript:current.vendor = current.purchase_order.vendor.toString()', which we thought would pass the sys_id of the value, but it does not.

Any suggestions?

Thanks,

Charles

1 ACCEPTED SOLUTION

If you still cannot get the default value to work another alternative is to use a display business rule to save the sys_id and display value of the vendor in the g_scratchpad, then populate it with an onLoad client script.



Example BR:



When: Display


g_scratchpad.vendorID = current.purchase_order.vendor;


g_scratchpad.vendorName = current.purchase_order.vendor.getDisplayValue();



Example CS:



function onLoad() {


        g_form.setValue('vendor', g_scratchpad.vendorID, g_scratchpad.vendorName);


}



http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices


View solution in original post

18 REPLIES 18

nthumma
Giga Guru

'javascript:current.vendor = current.purchase_order.vendor.toString()'



should this be 'javascript:current.vendor = parent.purchase_order.vendor.toString()'



since you said "we need to set the default value on the Vendor field to be the same as the Vendor field on the parent Purchase Order."


Hi there,



Thanks for the help. The field 'purchase_order' is on the Line Item form, which is why we were not using 'parent'. We tried this suggestion anyway but this does not work either.


Ch


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Charles,



All you need in the default value section is: javascript:current.purchase_order.vendor.toString();



The default value is basically asking you for a value, not for you to assign it through js if that makes sense.


Thanks Brad - unfortunately this is not working for us.