The CreatorCon Call for Content is officially open! Get started here.

g_form.setValue for reference field doesn ´t work as setting manually

diegobermudez
Tera Expert

Hi everyone,

We have done a Client script similar to OOTB "(BP) Set Location to User" wich sets the location of a incident same as caller.location when the caller is changed. Our script is equally to this OOTB but it sets the company.

The script seems to work perfectly, it sets the correct value for the company.

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || (g_form.isLiveUpdating && g_form.isLiveUpdating()))

return;

if (newValue == '') {

g_form.setValue('company', '');

return;

}

if (!g_form.hasField('company'))

return;

var caller = g_form.getReference('caller_id', setCompany);

}

function setCompany(caller) {

if (caller){

g_form.setValue('company', caller.company, caller.company.name);

}

}

The problem is when we try to use the company value before saving the record. I explain it....

The field cmdb_ci on incident table is depending on company field.

When we set the company value using the script above in a New Record, the CI is not filtered by the company.

After saving the record, it works perfectly and the CI is filtered by company but it doesn ´t work before submit.

If after the script sets the value of company, we select company manually again, CI is filtered by company without needing to save/submit

So we are thinking that g_form.setValue() for a reference field is not the same that select the value of that field manually as we can see with our tests.

Is there any wayof do a set Value for a refefence field wich do the same of selecting it manually that can override this behavior?

Thanks and regards,

1 ACCEPTED SOLUTION

diegobermudez
Tera Expert

I discover this behavior only occurs if List v3 are activated. I opened a case in HI-Portal and support team recognized the issue but notify to me they are not going to provide a solution as List v3 are deprecated in London. 

View solution in original post

9 REPLIES 9

Shusovit
Mega Expert

Hope this will help.



Use the setValue() displayValue parameter for reference fields



Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


As you can see in the script, I ´m setting the display value correctly:



g_form.setValue('company', caller.company, caller.company.name);  



So I think that is not the problem.....



Thanks!


Dubz
Mega Sage

How are you filtering your CI field? if you're doing it with a script include you should still be able to pull out the current value of the company field after it has been changed on the form before save/submit.


No, I ´m not using script include. The field is filtered by dependant OOTB:


find_real_file.png



So, there is any way to do this function when I set the company value by using setValue(field,id,name)?



Thanks