- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 05:17 AM
Hello all,
We need to use an onChange client script to populate a read-write reference field with the value shown on another read-only reference field. The issue is that the read-only field is itself a reference field on a different table...
We have references to the Department table (cmn_department) on both our Vendor and Purchase Order tables:
- On the Vendor table every Vendor has a read-only entry in the Department field.
- On the PO table (shown below) we have a reference to the Vendor table, and below this are four Vendor table fields including a read-only view of the Department field.
- Below this, there is a read-write Department reference field on the Purchase Order table, and this now needs to be populated with the same department as shown above whenever the Vendor is changed.
The script is clearly missing something but I would be grateful if someone could point us in the right direction:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var vendor = g_form.getValue('vendor');
var vendor1 = new GlideRecord('core_company');
vendor1.addQuery('name', vendor);
var dept //We need to add the correct script here to retrieve the department value from the vendor
if(vendor.hasNext()){
g_form.setValue(('department') , dept);
}
}
Thanks very much
Charles
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 05:45 AM
Try this script.In place of bold text write down the department field name used in core_company table.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var vendor = g_form.getValue('vendor');
var vendor1 = new GlideRecord('core_company');
vendor1.addQuery('sys_id', vendor);
vendor1.query();
if(vendor1.next()){
g_form.setValue('department' , vendor1.u_department);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 05:40 AM
Hi Russells,
After you get the department from core_company table then you may glide record to "cmn_department" table and get the object and then populate the same value using g_form.setValue.
Hoping this helps.
Regards,
Dhruv Chandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 05:45 AM
Try this script.In place of bold text write down the department field name used in core_company table.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var vendor = g_form.getValue('vendor');
var vendor1 = new GlideRecord('core_company');
vendor1.addQuery('sys_id', vendor);
vendor1.query();
if(vendor1.next()){
g_form.setValue('department' , vendor1.u_department);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 06:11 AM
...as easy as that! Thank you