Account Heirarchy Query

Sam Ogden
Tera Guru

Hi All,

On service Now we are using the Account Heirarchy model as some of our clients have multiple brands.

Client 1 has :

Brand A

Brand B

Brand C

Client 2 has no child brands

On our customer portals we have a script includes that finds the logged in users company and any child companies linked to it.   So if a user was a member of client 1 the would see client one + brands A-C and see all calls for these brands and be able to raise a ticket under any of those brands.

2 of our clients have no agreed a partnership on a new brand.   This would mean that for the particular band e.g. 'Brand D' people from Client 1 and people from Client 2 would need to see these tickets and raise tickets for this brand.   However people from client 2 would not be able to see or raise for brands A-C

What would be the best way to achieve this as from what I can tell in SN there is not the possibility in the Accounts module to add a child to multiple parents.

Thanks

Sam

1 ACCEPTED SOLUTION

Patrick Schult2
Giga Guru

As far as your parent/child path question for how to show the top company's child brands, I recommend you look at using the Account Path and Account Code fields on the Account table. Each Account has an automatically generated code, which gets placed into the Account Path value. Account Path tells you the hierarchy of the given Account.



The reason this is helpful is that you already know which company the logged in user belongs to, so you can therefore easily look at the top-most company via the Account Path. Then, because you have the top-most company's Account Code, you can turn around and do a simple query for any company that has code in its path. See the screenshots for an example.



Maybe look at setting up Partner access for the 2 companies that are related to each other. That sounds like an unusual situation but that sounds reasonable based on the information you provided already.


View solution in original post

6 REPLIES 6

Sam Ogden
Tera Guru

My only thought on this is to have either a list collector field or a related list to a new M2M table on the contact table when we can add additional relationships to accounts on a contact by contact basis



Currently the script include is as below.   If I added a new list collector field how would I amend the below script to do its current lookup but then to also check a new list collector field on the customer_contact table, and return all the accounts relevant i.e. the contacts company + child companies + any company in the new field?



It is the getCompCDL in the below script that is currently used on the portal.



Script Includes



var CDL_getDetails = Class.create();
CDL_getDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {    
//Gets the Parent and Child Companies of the logged in user on the portal.   Specific sys_id returns for BDML users
getComp : function()
{
  var sysid=[];
  var user = gs.getUserID();
  var company;
  if (gs.getUser().isMemberOf('Customer Portal Users - BDML')){


                            return 'sys_idIN' + gs.getProperty('bdml.sysid');


} else if (gs.getUser().isMemberOf('Customer Portal Users - BDML & Zenith')){


                      return 'sys_idIN' + gs.getProperty('bdml.zenith.sysid');


} else{
  var usr = new GlideRecord('sys_user');
  usr.addQuery('sys_id',user);
  usr.query();
  if(usr.next())
    {
    company = usr.company;
  }
  if( company != '' ) {
    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(',');
  } }

},

getCompCDL : function() {
  var sysid=[];
  var company,com;
  var user1 = gs.getUserID();
    if (gs.getUser().isMemberOf('Customer Portal Users - BDML')){


                            return 'sys_idIN' + gs.getProperty('bdml.sysid');


} else if (gs.getUser().isMemberOf('Customer Portal Users - BDML & Zenith')){


                      return 'sys_idIN' + gs.getProperty('bdml.zenith.sysid');


} else{
  var usr = new GlideRecord('sys_user');
  usr.addQuery('sys_id',user1);
  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(',');
  }
  }
},


      type: 'CDL_getDetails'
});


Patrick Schult2
Giga Guru

As far as your parent/child path question for how to show the top company's child brands, I recommend you look at using the Account Path and Account Code fields on the Account table. Each Account has an automatically generated code, which gets placed into the Account Path value. Account Path tells you the hierarchy of the given Account.



The reason this is helpful is that you already know which company the logged in user belongs to, so you can therefore easily look at the top-most company via the Account Path. Then, because you have the top-most company's Account Code, you can turn around and do a simple query for any company that has code in its path. See the screenshots for an example.



Maybe look at setting up Partner access for the 2 companies that are related to each other. That sounds like an unusual situation but that sounds reasonable based on the information you provided already.


Hi Patrick,



Thanks for the above information that is useful.



How does the partner access work?



Thanks



Sam


There's documentation on how bi-directional relationships are setup in the Docs site here: Set up customer relationships



Basically it's a record that says account A is related to account B via relationship XYZ. You can leverage this in any custom scripts you have to design to make your custom lookups work like you want.