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

I would validate a few things:



1. Your fields are actually named vendor and not u_vendor


2. Both the purchase order and vendor (on purchase order) fields have values when the form is initially loaded


3. This code is in the default value section on the dictionary entry.



Also, could you post a screenshot of the default value field on the dictionary.


Hi   Brad,



1) Yes, both system 'vendor' fields - not created by us.


2) Yes, both of these are populated and saved before we open a new line item


3) Yes indeed - image below...



find_real_file.png


Thank you!



Ch


i need to make a refernce field default to loggedin user


can anyone help me out plz?


Hi Kiran,



If you want the field to show the name of the person who created the record then the easiest thing to do is to personalise the dictionary on the sys_user reference field, select the Advanced view, click the 'Default Value' tab, tick 'Use dynamic default' and select 'Me'.



Cheers,



Charles


FYI -



A few days ago I noticed on a brand new Istanbul instance that "Me" wasn't available as a default value, only as a filter. If you don't see "Me" as an option for your default value, navigate to System Definition> Dynamic Filter Options, find "Me" and check the box that allows it to be used for a default value.



find_real_file.png