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

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


That works a treat! Thank you Chuck - I have learned something new today .



I'm still not sure why the original default script wan't working, but nomatter.



Charles


I'm glad you got your question answered. Thank you for participating in the community.


Hey chuck



I have the same issue and would like to make the Default value as none for a reference field on Knowledge table. Right now we have field "Knowledge Management group" and it has 'Knowledge approver" as default value. I would like to change it to none at Draft status and it should be same as earlier in other stages. Any thoughts on this ? I was trying to modify the script but it doesnt effect



The below is the default value we have currently



javascript:new GBPKnowledgeUtil().getGroupManual(current.u_company, 'L1');



Regards