The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Circular parent/child relationship

ericeger
Tera Guru

Hi everyone,

I'm working on creating an organization table that will have a reference to parent organizations.   My concern is that when I create or change an organization, it should not be able to find a parent organization where the parent organization is already a child organization. For example, Company 1(child) has a parent of Company 2.   If I go back to Company 2 and select the Parent Organization reference field, I don't want to see Company 1 in that list because its already a child of Company 2.

I was looking around the reference qualifiers and didn't see anything that could help me.   Any help in the right direction would be great, thanks!

1 ACCEPTED SOLUTION

your code should look like that


var CompanyList = Class.create(); CompanyList.prototype = Object.extendsObject(AbstractAjaxProcessor, {      


getCompanyList: function(CurrSysID)


{


var CompanyList= "";


var gr = new GlideRecord("x_mpaii_snap_trace_organizations");


gr.addEncodedQuery("sys_id!=" + CurrSysID + "^parent_organization!=" + CurrSysID);


gr.query();


while(gr.next())


{


CompanyList += gr.sys_id + ",";


}


return "sys_idIN" + CompanyList;      


},    


  type: 'CompanyList' });


test out this code and let me know whether it works or no


View solution in original post

12 REPLIES 12

in the script include remove parent and instead add parent_organization . gr.addEncodedQuery("sys_id!=" + CurrSysID + "^parent_organization!=" + CurrSysID);


I tried adding that and it's still getting hung up at



var gr = newGlideRecord("x_mpaii_snap_trace_organizations");



I can confirm that the table name is correct as well, it is a new table I created


Hi Eric check the missing semi colon at line 11 and make sure that you are selecting application scope


Hi Ahmed,



I did fix the semi-colon(good catch) and my application scope is currently for my application


ApplicationScope.PNG


your code should look like that


var CompanyList = Class.create(); CompanyList.prototype = Object.extendsObject(AbstractAjaxProcessor, {      


getCompanyList: function(CurrSysID)


{


var CompanyList= "";


var gr = new GlideRecord("x_mpaii_snap_trace_organizations");


gr.addEncodedQuery("sys_id!=" + CurrSysID + "^parent_organization!=" + CurrSysID);


gr.query();


while(gr.next())


{


CompanyList += gr.sys_id + ",";


}


return "sys_idIN" + CompanyList;      


},    


  type: 'CompanyList' });


test out this code and let me know whether it works or no