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

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 

 

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.

 

 

 

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

You have reference field on Table B which is referring to Table A, right?

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

shloke04
Kilo Patron

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);

find_real_file.png

Also in above Script "Incident" is a field on Table B(Incident task) which is connecting to Table A as shown below:

find_real_file.png

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);
    }
}

find_real_file.png

This is working for me in my PDI.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

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.