Hide empty reference field

Diana27
Tera Guru

Hi,

 

I have 2 reference variables.  Variable A and Variable B.  Variable A is a reference to cmn_cost_center.   Variable B is a reference to a custom table and has a reference qualifier for Variable A.  When the user selects an option from Variable A it populates Variable B with a list of items associated to Variable A for the user to select.   That is working correctly.   

 

Here is what I cannot seem to get to work:

If the user selects an option from Variable A that does not have any associated items to Variable B then Variable B should be hidden.

 

What is the best way to hide Variable B if it does not get populated?

 

Thank you in advance for any assistance,

Diana 

1 ACCEPTED SOLUTION

Hi Diana,

 

This script wont work, you have to write a GlideAjax and call a script include. In there you need to mimic the same query as your Reference Qualifier (u_active=true^u_type=opex_id^u_cost_center='+ current.variables.cost_center;) and check if there are any options present to be shown in variable B, if this count is more than 0 then return back a flag value based on which you can show variable B

-Anurag

View solution in original post

5 REPLIES 5

Ahmmed Ali
Mega Sage

Hello @Diana27 

 

How are you populating the existing variable A values in variable B? is it client script? can you post the script you are using?

 

Ideally you can check in the same script and if there are no items, then you can hide the variable B.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi Ahmmed,

 

I am using a reference qualifier:

javascript: var query = ''; query+= 'u_active=true^u_type=opex_id^u_cost_center='+ current.variables.cost_center;

 

Thank you,

Diana

Anurag Tripathi
Mega Patron
Mega Patron

Make Variable B hidden by default(onload)

Write a Client script that rinds on change of Variable A, check if there are values for Variable B (You might need a Glide Ajax Call here), And if there are Values for Variable B then show it, otherwise leave it hidden.

 

-Anurag

Hi Anurag,

 

I've created a catalog onChange client script for Variable A  to check the length of Variable B and to hide it if it is 0.  But it is always hiding Variable B.  It doesn't see that there are options that have not been selected.

In the sample below cost_center is Variable A and opexid is Variable B.

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ccenter='';
var opex ='';
ccenter = g_form.getValue('cost_center').length;
opex = g_form.getValue('opexid').length;
if (ccenter != 0 && opex == 0){
g_form.setDisplay('opexid',false);
}
}

 

Thank you,

Diana