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

Imran1
Giga Guru

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

11 REPLIES 11

Hi Imran,

In place of this static sys_id 8336ea93db101410d3edf5f51d961987, from where do you want to get it?

Hi Asif,

The field 'contract_suppliers' is a reference list field which I am using to get the values from another table field as you are aware when we do getValue we get the sys id and in client side I don't have option as getDisplayValue and even I tried getDisplayBox as below but it didn't worked.

var supValue =  (g_form.getDisplayBox('contract_suppliers').value);

var sup = g_form.getValue('contract_suppliers');

 

Regards,
Imran

Hi Imran,

var sup = g_form.getValue('contract_suppliers');

This line gets you sys_id of the value that you have selected in the field contract_suppliers.

Now you are using this line

if(sup.indexOf('8336ea93db101410d3edf5f51d961987')>-1){// Enterprise

Why are you hardcoding these? Where are they stored and what exactly you want to compare?

 

Hi Asif,

I understand, I shouldn't hard code that is the reason I trying to dot walk from to string field in the target table from the reference field. 

For now I am using the hardcoded values as workaround.

Regards,
Imran

yes, so when you use g_form.getReference what is the issue you are facing:

Did you correct the changes that i have mentioned?