Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use reference qualifier in related list edit button ?

Akhil Kumar1
Tera Guru

Hi All ,

When associating records in a Related List through the slus hbucket (i.e. clicking the "Edit...") button, how do we apply a reference qualifier on the list of possible selections based on values of the current record?

1. I have created a Advance reference qualifier and it's working fine in the form level, i have added a script and it's calling in advance reference qualifier

2.When i click the edit button in the related list there also i need to apply his reference qualifier

3. i have read in wiki this link related to this Reference Qualifiers - ServiceNow Wiki

(Related Lists and Reference Qualifiers)

Kindly help me on the same..

Related Lists and Reference Qualifiers

Whenever you edit a reference field from a related list, it might be necessary to know which related list the reference field is on in order to properly build the reference qualifier for the field. This occurs when the same field appears on different related lists and the context is necessary to know how to properly qualify the reference values.

To do this, configure the list control for the related list and fill in the List edit tag with any tag you choose. This tag value will be available to the advanced reference qualifier function as a variable named listEditRefQualTag. For example, your advanced reference qualifier script include can look like this:

// Advanced reference qualifier on the CI Relationship Child field that takes into account// the related list that we are editing the child field on, if the field is being editing// from a tagged related list.      cmdb_rel_ci_child_refQual:function()   {           if (listEditRefQualTag == "application")       return "sys_class_name = cmdb_ci_appl";       if (listEditRefQualTag == "database")       return "sys_class_name = cmdb_ci_database"       }
1 ACCEPTED SOLUTION

courtenay1
Tera Expert

There seems to be a few answers on the Community about filtering list collectors, most referring to SNGuru's client side filtering, and others referring to the very old and obfuscated "mtmquerygenerator" method.


But the easiest and most straight forward approach is to use the "parent" object which is available to reference qualifier scripting when editing a many-to-many related list.


The post in Deepak's answer uses the same "parent" object. However "parent" won't be available when updating an existing many-to-many record form opposed to list collector editing.


Regardless, both scenarios can be handled in the one reference qualifier.


Here's a common use case example and solution - filtering Incident related Affected CIs based on the Caller's Assigned to CIs:


1. Create a Script Include ...
Name:affectedCIFilterIncident


Script:


var affectedCIFilterIncident = Class.create();



affectedCIFilterIncident.setRefQual = function() {

// Deduce the parent CI object by checking for existence of parent and current globals.
var theParent;
// 'parent' object is the parent form GlideRecord which is available to list collectors and ACLs
if (typeof parent !== 'undefined') {
  theParent = parent;
} else if (typeof current !== 'undefined') {
  theParent = current.task.getRefRecord();
}

if(theParent.sys_class_name != 'incident')
  return;

var myCaller = theParent.getValue("caller_id");
if (myCaller.nil())
  return;

return "assigned_to=" + myCaller;
};



2. Update the dictionary for the CIs Affected field Configuration Item [task_ci.ci_item] with a Reference qualifier of:


javascript:affectedCIFilterIncident.setRefQual()



Testing for either the "parent" or "current" objects in the script will allow the reference qualifier to work editing in a list collector, and when clicking into and updating an existing record.
If users are always going to be editing by list collector only then the script can be simplified further ...


var affectedCIFilterIncident = Class.create();



affectedCIFilterIncident.setRefQual = function() {

// 'parent' object is the parent form GlideRecord which is available to list collectors and ACLs
if(parent.sys_class_name != 'incident')
  return;

var myCaller = parent.getValue("caller_id");
if (myCaller.nil())
  return;

return "assigned_to=" + myCaller;
};


View solution in original post

7 REPLIES 7

john_roberts
Mega Guru

If you are trying to filter a many-to-many list it's a little tricky. Thanks for giving me a reason to finally get this off my blog to-do list.


Hope this helps. You'll just need to adjust where the attributes go based on your needs.


Filter Edit List Reference List Results (m2m lists) — CAVUCode


Hi John Roberts,



Thanks for your reply..


i have tried the same thing in demo instance as per your blog


but i am not able to achieve this ..for global table i am not able to create a BR of type( when to run-none)it's coming before as default..


the same example i tried in demo for a testing purpose..



Kindly help or provide your suggestion for the same


It's noted in the post that you might have trouble in newer instances. I recommend finding an existing legacy OOB rule. Search for active=false, and script contains lookup.


Then use the form context menu to insert a copy of the rule. Then you can modify the name and script for you new need.



John


I tried this and the script never gets executed...