- 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 10:01 PM
No. u_crayons is the field for table A
gr.addQuery("sys_id",current.u_crayons); field for table A
gr.addEncodedQuery('u_crayons',true); field for table A
Should both of these be for table b instead of table A? See above
Table B is the the table where the field should be hidden
So we are hiding table b field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 10:09 PM
BR should be on Table B. You are gliding into table A which is also correct.
What I was asking is 'u_crayons' this field should be on Table A and referring to table B.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 10:12 PM
You have reference field on Table B which is referring to Table A, right?
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 10:04 PM
Hi,
Please find the steps below to make you understand on how you can achieve this:
1) For example, for me let's take below scenario:
Table A = Incident
Table B = Incident Task
Now as per your requirement, based on a Field in Table A(Incident) i will hide a field on Table B (Incident Task)
1) Write a Display Business Rule on Table B i.e. Incident Task for me as shown below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.getParentField =current.incident.FIELDNAME.toString(); // Replace "FIELDNAME" with your checkbox field name based on which you want to hde or show
})(current, previous);
Also in above Script "Incident" is a field on Table B(Incident task) which is connecting to Table A as shown below:
Now write an On Load Client Script On Table B itself and use the script below:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.getParentField == 'false') {
g_form.setDisplay('FieldName', false);
}
}
This is working for me in my PDI.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 10:45 PM
It's not working. I think something else is going on here. It's not the code, it may be the way the form is set up.
The 2 tables are reference/related to each other. Reference ID numbers are created on table A and then selectable on Table b. That reference number will then need to be selected on table B before it will know which fields to hide and what to show based on the choices on form A which is contained in the reference ID.
Since a reference number will need to be selected on form B first before the system knows to hide the field , I think its making the function a little tough. I may need to talk to a co worker to figure this out. It may be a bit much to explain here. I don't understand how this would work on load if the reference number from form A hasn't been selected yet on form b. The reference number contains all the information selected on Form A.
I think you have explained it correctly and your code would work, but I think this is a weird scenario.