How to use reference qualifier in related list edit button ?

Akhil Kumar1
Mega Sage

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

Deepak Ingale1
Mega Sage

Pre-filter slushbucket



This post should assist you.


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


Thanks, that works perfectly! I tried to use listEditRefQualTag before, but it was always undefined although i have set it using list control. (Tested in Helsinki)