- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 02:55 AM
Hello all,
On Table 'proc_po' we have a requirement to populate a reference field 'u_final_category_detail' which references the table 'u_final_category_detail'.
Table 'proc_po' also has the reference field 'u_cost_center', which references the table 'cmn_cost_center'.
Table 'cmn_cost_center' has a List field 'u_final_category_detail' which is referencing Table 'u_final_category_detail'.
The requirement is to populate the reference field 'u_final_category_detail' on the 'proc_po' table only if there is only one entry in the list field on table 'cmn_cost_center'.
How do we amend the following script to check for only one entry on the list field?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var category = g_form.getValue('u_cost_center);
var category1 = new GlideRecord('cmn_cost_center');
category1.addQuery('sys_id', category);
//We need a script here to check to check if the 'u_final_category_detail' list field has only one entry, and only to proceed if so.
category1.query();
if(category1.next()){
g_form.setValue('u_final_category_detail' , category1.u_final_category_detail);
}
}
Thanks very much for any help.
Charles
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 03:13 AM
Modifying a part of your code:
var category = g_form.getValue('u_cost_center);
var category1 = new GlideRecord('cmn_cost_center');
category1.addQuery('sys_id', category);
//We need a script here to check to check if the 'u_final_category_detail' list field has only one entry, and only to proceed if so.
category1.query();
if(category1.next() && category1.u_final_category_detail.split(',').length == '1'){
g_form.setValue('u_final_category_detail' , category1.u_final_category_detail);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 03:24 AM
Just would add two things:
1) You should consider making the gliderecord aysnchronous (it'll flag up on the ACE report otherwise).
2) You should first check if the length is one before doing the gliderecord. That way you only do the DB query when actually required.