- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 08:06 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:10 PM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:10 PM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:24 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:27 PM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:39 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 09:51 PM
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');
Regards,
Abhijit
ServiceNow MVP