g_form.getReference not working for list reference field when dot walked

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2020 04:37 AM
Hi All,
I have a list reference field (referencing to contract table) and I need to set values in another field called approvers basis on contract that someone selects; for example if a person selects contract a, contract b. I need to set the approver as x & y and if a person selects contract d, contract e. I need to set the approvers as A&B etc.
For doing this I am using an on-change client script and calling the getReference() method
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var suppliers = g_form.getReference('contract', doAlert);
}
function doAlert(caller) { // reference is passed into callback as first arguments
if (caller.supplier) // here I am dot walking to the supplier field within the contract table
g_form.setValue('internal_use', caller.supplier);
var rel = g_form.getValue('internal_use');
g_form.addErrorMessage(rel);
}
if (suppliers.indexOf('HAA') > -1) {
g_form.setValue('approvers', '10a694bfdbd85410d3edf5f51d9619ac,6043e934db429810aec35665dc96193f');
}
if (suppliers.indexOf('ABC') > -1 || suppliers.indexOf('Enter') > -1) {
g_form.setValue('approvers', '8126d0bfdbd85410d3edf5f51d96197b,494e240ddb0590101fedff461d961982');
}
This script doesn't seem to work even the addError message doesn't through any error
Not sure if I am doing rightly, basically I need to get the value of another field from the reference field table and basis on that I need to set the approvers
Any help is highly appreciated. Could you please try it in your instance within client script
Regards,
Imran

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2020 08:46 AM
Hi Imran,
Can you try below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var suppliers = g_form.getReference('contract', doAlert);
function doAlert(suppliers) {
var rel=suppliers.supplier;
alert('Supplier is '+suppliers.supplier); //if supplier is reference it will return sys_id
if (rel.indexOf('HAA') > -1) {
g_form.setValue('approvers', '10a694bfdbd85410d3edf5f51d9619ac,6043e934db429810aec35665dc96193f');
}
else if (rel.indexOf('ABC') > -1 || suppliers.indexOf('Enter') > -1) {
g_form.setValue('approvers', '8126d0bfdbd85410d3edf5f51d96197b,494e240ddb0590101fedff461d961982');
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 10:15 AM
Hi Jaspal,
Thank You for modifying the script, I created a new client script utilizing the code snippet you shared, I disabled the old one I had. It doesn't seem to work nor I get any alerts
Regards,
Imran