Reference Qualifier with Script Include in List Collector Variable - not returning value

Colleen1
Tera Contributor

We have a requirement to display all devices per a parent site in a list collector.  When I call the script include, I can see in the system logs that the strQry value is being populated but shows 'no matches found' in the list collector field on the form (screenshot below).   Or maybe there is there a way to add that to the query "u_current_fw_versionISNOTEMPTY^u_current_fw_versionNSAMEASu_target_firmware_version^u_active_policy_exceptionISEMPTY" that is needed and not use a script include but I don't know how to add the filter for the parent site as well.   I am not sure what I am missing here and would very much appreciate any help here.  

 

Here is my list collector:

Colleen1_0-1701983723873.png

The script include is below: 

function ListFieldSiteAssets() {
//var ListFieldSiteAssets = Class.create();

  var strParentSite = current.variables.parent_site; //user chosen in variable
   gs.log("parent site " + current.variables.parent_site + " var " + strParentSite );
  if (strParentSite!= '') {
     //if not empty
         strQry = '^sys_idIN' + _getFSAssetsIds(strParentSite); //get the list of models at the parent site
        gs.log("strQry " + strQry );
     }
    return strQry; //return the query
}
function _getFSAssetsIds(parent) {

  var strFSAssets = '';

  // Get all Field site assets
gs.log( " parent in function " + parent );
  var grFSA = new GlideRecord('u_field_site_assets');
  grFSA.addQuery('u_connected_device', parent);  // u_connected_device is the name for the parent site on the table
 grFSA.addEncodedQuery('u_current_fw_versionISNOTEMPTY^u_current_fw_versionNSAMEASu_target_firmware_version^u_active_policy_exceptionISEMPTY');
  grFSA.query();
  while(grFSA.next()){
    if (strFSAssets.length > 0) {
      // build a comma separated string of groups if there is more than one
         strFSAssets += ',' + grFSA.u_mobile_friendly_name;
      } else {
          strFSAssets = '' + grFSA.u_mobile_friendly_name;
      }
  }

  return strFSAssets;

}
  // type: 'ListFieldSiteAssets'
//};
 
Here is what is showing in the system logs for the 'strQry' variable and it is correct.  
 Colleen1_2-1701984261277.png

 

Thank you,
Colleen
1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Hi Colleen,

You are suppose to return sys_id to the reference qualifier. Could you please fix the script accordingly?

function ListFieldSiteAssets() {
//var ListFieldSiteAssets = Class.create();

  var strParentSite = current.variables.parent_site; //user chosen in variable
   gs.log("parent site " + current.variables.parent_site + " var " + strParentSite );
  if (strParentSite!= '') {
     //if not empty
         strQry = '^sys_idIN' + _getFSAssetsIds(strParentSite); //get the list of models at the parent site
        gs.log("strQry " + strQry );
     }
    return strQry; //return the query
}
function _getFSAssetsIds(parent) {

  var strFSAssets = '';

  // Get all Field site assets
gs.log( " parent in function " + parent );
  var grFSA = new GlideRecord('u_field_site_assets');
  grFSA.addQuery('u_connected_device', parent);  // u_connected_device is the name for the parent site on the table
 grFSA.addEncodedQuery('u_current_fw_versionISNOTEMPTY^u_current_fw_versionNSAMEASu_target_firmware_version^u_active_policy_exceptionISEMPTY');
  grFSA.query();
  while(grFSA.next()){
    if (strFSAssets.length > 0) {
      // build a comma separated string of groups if there is more than one
         strFSAssets += ',' + grFSA.sys_id;
      } else {
          strFSAssets = '' + grFSA.sys_id;
      }
  }
  return strFSAssets;

}
  // type: 'ListFieldSiteAssets'
//};

 


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @Colleen1 , 

As per standard practice, I don't see any function call from List Collector , even you are calling the script include name itself and there is no any function/method defined in script include for calling from outside , you create a inline function [ _getFSAssetsIds ] for internal check.

 

review any existing script include in your system and create a function for call and update the List Collector ref qual

like this 

javascript&colon; new ListFieldSiteAssets().<methodName()>

 

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

SanjivMeher
Kilo Patron
Kilo Patron

Hi Colleen,

You are suppose to return sys_id to the reference qualifier. Could you please fix the script accordingly?

function ListFieldSiteAssets() {
//var ListFieldSiteAssets = Class.create();

  var strParentSite = current.variables.parent_site; //user chosen in variable
   gs.log("parent site " + current.variables.parent_site + " var " + strParentSite );
  if (strParentSite!= '') {
     //if not empty
         strQry = '^sys_idIN' + _getFSAssetsIds(strParentSite); //get the list of models at the parent site
        gs.log("strQry " + strQry );
     }
    return strQry; //return the query
}
function _getFSAssetsIds(parent) {

  var strFSAssets = '';

  // Get all Field site assets
gs.log( " parent in function " + parent );
  var grFSA = new GlideRecord('u_field_site_assets');
  grFSA.addQuery('u_connected_device', parent);  // u_connected_device is the name for the parent site on the table
 grFSA.addEncodedQuery('u_current_fw_versionISNOTEMPTY^u_current_fw_versionNSAMEASu_target_firmware_version^u_active_policy_exceptionISEMPTY');
  grFSA.query();
  while(grFSA.next()){
    if (strFSAssets.length > 0) {
      // build a comma separated string of groups if there is more than one
         strFSAssets += ',' + grFSA.sys_id;
      } else {
          strFSAssets = '' + grFSA.sys_id;
      }
  }
  return strFSAssets;

}
  // type: 'ListFieldSiteAssets'
//};

 


Please mark this response as correct or helpful if it assisted you with your question.

This worked perfectly!!! Thank you !!!