Advance Reference Qualifier depending on other field

Gaurav Rotke1
Kilo Guru

Hi All,

On the form there are two fields

one is parent field and one is type field. As type changes to 1 I want parent filed should only show the record with which are type 1 and when type 2 is selected, the parent filed should show type 1 and type 2 record.

I tried coding few times but its only showing either type 1 records for all the type or its showing type 1 and 2 records for all the types, its not changing as we change the type filed.

I am using advance reference qualifier with script include. Any suggestion or improvised code would be helpful.

Thank you in Advance

 

Please refer the image for code

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Please provide more details, such as scripts and screen shots.

Thank you for the reply, added the script in the question.

So, I've reviewed your images, and re-read the question.

Basically it should work, but I'll provide some pointers to look at.

 

When calling the script include, you need to include parentheses after the class name, like this:

javascript: new scoped_application.ParentFilter().parent(current.sys_id.toString());

 

Like Sagar Pagar already suggested, it seems unnecessary to do another query in the script include.

It will be enough if you return a valid encoded query as a qualifier, and you already have that in the script.

So the script could be a lot simpler (example below).

 

Make it a habit to use the getValue() method, when retrieving data from the record.

 

Also make sure you have an else-statement in case no record was found, or not a valid value was found.

You should have a default query to use in those cases.

 

 

parent: function(recordID){

  var type = '';
  var resultEncodedQuery = '';

  var someGR = new GlideRecord('tablename');
  if (someGR.get(recordID)){
    type = someGR.getValue('u_type');  // use getValue

    if (type == 'Type A'){
	resultEncodedQuery = 'active=true^tablename_type=' + type;
    }
    else if (type == 'Type B'){
	resultEncodedQuery = 'active=true^tablename_type=' + type + '^ORtablename_type=Type A';
    }
    else {
	resultEncodedQuery = 'active=true';  // add a default query
    }

  }
  else {
	resultEncodedQuery = 'active=true';  // add a default query
  }

  return resultEncodedQuery; 
}

 

 

And if it still isn't working, add debugging statements to verify you get a record, that the record has the value expected, and so on.

Sagar Pagar
Tera Patron

Hi @Gaurav Rotke1,

 

Try this in advanced reference qualifier with updating the field name and type values. Let me know it works or not?

javascript: if (current.type == 'type1') {
	"active=true^type=type1";
} else if (current.type == 'type2') {
	"active=true^type=type1^ORtype=type2";
} else {
	"active=true";
}

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow