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

Reference Qualifier to hide a field

paradise624
Tera Contributor

I have a requirement to hide a field based on a field on another table.

For example, if field A on table A = false, hide field b on table b.

So I'm using a reference qualifier to make this field B dependent on Field A. I completed the following fields in the Reference Specification tab

For the reference: I selected the table A

For the reference qualifier I used :"simple"

For the reference qualifier condition: I used the condition: If the field A is true 

Field A is True

For some reason this does not hide b on table b. Why is this reference qualifier not working?

1 ACCEPTED SOLUTION

You missed current record filter like from table B you should first get record which is referenced in Table A record.

e.g.

var gr = new GlideRecord('Table A');

gr.addQuery("sys_id",current.table_a_reference_field_name);//this field name should be on Table B form
gr.addEncodedQuery('FIELD A',true);
gr.setLimit(1);
gr.query();
if(gr.hasNext())
{
g_scratchpad.makeVisible = true;
}

else
{
g_scratchpad.makeVisible = false;
}

All other part of the script looks good to me.

Try printing message in BR and see what value it is setting

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

15 REPLIES 15

You missed current record filter like from table B you should first get record which is referenced in Table A record.

e.g.

var gr = new GlideRecord('Table A');

gr.addQuery("sys_id",current.table_a_reference_field_name);//this field name should be on Table B form
gr.addEncodedQuery('FIELD A',true);
gr.setLimit(1);
gr.query();
if(gr.hasNext())
{
g_scratchpad.makeVisible = true;
}

else
{
g_scratchpad.makeVisible = false;
}

All other part of the script looks good to me.

Try printing message in BR and see what value it is setting

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

I'm a little confused. 

gr.addQuery("sys_id",current.table_a_reference_field_name)

 

Where you have sys_id, should I be pulling a sys id from one of the fields?

Also current.table_a_reference_field_name, should this be the field from field A (the field we are running the query on) or field b, the field we are looking to hide?

 

 

I am assuming you have written that BR on table B so you must be having one reference field referring to table A on table B so filter should be like below,

gr.addQuery("sys_id",current.field_referencin_to_table_a);

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Yes, I've written the rule on table b:

Example:

Table A: Field Name: Crayons u_crayons

Table A: Table Name: x_crayons_titles

 

Table B field Name: Colors   u_color

Table B: Table Name: x_color_titles

 

Example: Business rule written on Table B

 

var gr = new GlideRecord('x_crayon_titles');

gr.addQuery("sys_id",current.u_crayons);
gr.addEncodedQuery('u_crayons',true);
gr.setLimit(1);
gr.query();
if(gr.hasNext())
{
g_scratchpad.makeVisible = true;
}

else
{
g_scratchpad.makeVisible = false;

 

Does this look correct?

Hi,

if "u_crayons" this field is reference to table B ten script looks good.

In case it doesn't work try adding qoutes for boolean true for below line (sometime it doesn't work)

gr.addEncodedQuery('u_crayons','true');

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP