script includes and reference qual

Sam Ogden
Tera Guru

Hi All,

We have the below script includes which is used for an encoded query for a filter on a simple list widget on our service portal.

I want to use the same script includes for a reference qual on a variable u_brands.   This is a reference field as part of a variable set which will be used on some of our request items used on both the portal and the standard SN UI.   This will be to filter the reference field to show the logged in users company and any child companies associated to this company, as long as the users company is not CDL.   If it is CDL it should not filter and therefore show all the companies.

Currently this reference qual is not working and just returning all companies.   Any help on where I have gone wrong is greatly appreciated.

I've added the encoded query that is used on the portal (this is used to return all incidents for the logged in users company and any child company associated to it.   I don't want to be making any changes to the below script includes that will cause issue to this query that is already working.   If needed I will create a separate one).

Reference Qual: javascript:new CDL_getParentChild().getCompanyCDL(gs.getUserID());

find_real_file.png

Script Includes:

var CDL_getParentChild = Class.create();

CDL_getParentChild.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getCompanyCDL : function(user) {

  if(!user){

  user=gs.getUserID();

  }

  var sysid=[];

  var company,com;

  var usr = new GlideRecord('sys_user');

  usr.addQuery('sys_id',user);

  usr.query();

  if(usr.next())

    {

    company = usr.company;

    com = usr.email;

  }

  if( company != '' ) {

    if(com.indexOf('@cdl.co.uk')>= 0)

      {

      var compani = new GlideRecord('core_company');

      compani.query();

      while(compani.next()) {

        sysid.push(compani.sys_id.toString());

      }

      return sysid;

    }  

    var company1 = new GlideRecord('core_company');

    company1.addQuery('parent',company);

    company1.query();

    while(company1.next()) {

      sysid.push(company1.sys_id.toString());

    }

    sysid.push(company.sys_id.toString());

    return sysid.join(',');

  } else {

    var company2 = new GlideRecord('core_company');

    company2.addEncodedQuery('vendor=false^customer=false^NQcustomer=true');

    company2.query();

    while(company2.next()) {

      sysid.push(company2.sys_id.toString());

    }

    return sysid.join(',');

  }

},

type:'CDL_getParentChild'

});

Portal Filter:

find_real_file.png

1 ACCEPTED SOLUTION

Managed to get this working, ref qual and script includes used below:



Ref Qual: javascript:new KPMG_getDetails().getCompCDL(gs.getUserID());



Script includes:



getCompCDL : function(user) {


  var sysid=[];


  var company,com;


  var usr = new GlideRecord('sys_user');


  usr.addQuery('sys_id',user);


  usr.query();


  if(usr.next())


    {


    company = usr.company;


    com = usr.email;


  }


  if( company != '' ) {


    if(com.indexOf('@cdl.co.uk')>= 0)


      {


      var compani = new GlideRecord('core_company');


      compani.query();


      while(compani.next()) {


        sysid.push(compani.sys_id.toString());


      }


      return 'sys_idIN'+sysid;


    }


   


    var company1 = new GlideRecord('core_company');


    company1.addQuery('parent',company);


    company1.query();


    while(company1.next()) {


      sysid.push(company1.sys_id.toString());


    }


    sysid.push(company.sys_id.toString());


    return 'sys_idIN'+sysid.join(',');


  } else {


    var company2 = new GlideRecord('core_company');


    company2.addEncodedQuery('vendor=false^customer=false^NQcustomer=true');


    company2.query();


    while(company2.next()) {


      sysid.push(company2.sys_id.toString());


    }


    return 'sys_idIN'+sysid.join(',');


  }


},


View solution in original post

2 REPLIES 2

Sam Ogden
Tera Guru

Any suggestions on the above? or any further information required?



Thanks


Managed to get this working, ref qual and script includes used below:



Ref Qual: javascript:new KPMG_getDetails().getCompCDL(gs.getUserID());



Script includes:



getCompCDL : function(user) {


  var sysid=[];


  var company,com;


  var usr = new GlideRecord('sys_user');


  usr.addQuery('sys_id',user);


  usr.query();


  if(usr.next())


    {


    company = usr.company;


    com = usr.email;


  }


  if( company != '' ) {


    if(com.indexOf('@cdl.co.uk')>= 0)


      {


      var compani = new GlideRecord('core_company');


      compani.query();


      while(compani.next()) {


        sysid.push(compani.sys_id.toString());


      }


      return 'sys_idIN'+sysid;


    }


   


    var company1 = new GlideRecord('core_company');


    company1.addQuery('parent',company);


    company1.query();


    while(company1.next()) {


      sysid.push(company1.sys_id.toString());


    }


    sysid.push(company.sys_id.toString());


    return 'sys_idIN'+sysid.join(',');


  } else {


    var company2 = new GlideRecord('core_company');


    company2.addEncodedQuery('vendor=false^customer=false^NQcustomer=true');


    company2.query();


    while(company2.next()) {


      sysid.push(company2.sys_id.toString());


    }


    return 'sys_idIN'+sysid.join(',');


  }


},