- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 08:48 AM
Hi Team,
I have a requirement wherein I need to find all accounts under an hierarchy.Suppose I am on an account as highlighted in red below
I want to get the names of all the accounts in the hierarchy as below . Can someone tell me how to achieve it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 11:05 AM - edited 04-25-2024 11:06 AM
Hi Ankur,
The only way that I know of is to write a recursive script that starts at the top and queries for the next level of data. For each entry at that level, the recursion keeps drilling down until it reaches the bottom. There are several things to consider when setting up something like this. The most important one is where are you holding the data as you move between levels, etc. If you are not familiar with recursive programming, it can take a little getting used to.
Here is a simplistic version of a recursive function:
digDown : function(whatAccount, theData) {
var myTable = new GlideRecord("<your table name>);
myTable.addQuery("<account field>", whatAccount);
myTable.query();
while (myTable.next()) {
digDown(myTable.sys_id.toString, theData)
} else {
theData.push(myTavle.<identifier>.getDisplayValue());
return;
}
}
theData is an empty array that gets created before invoking the function. What will happen is that when it gets to the bottom of one leg of the hierarchy it will add that value to the array and go back to the next higher level where it will continue going through the rows selected until all have been done and them go back up a level. Of course you have some ohter options around how you store the data based on what else you need, etc.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 11:05 AM - edited 04-25-2024 11:06 AM
Hi Ankur,
The only way that I know of is to write a recursive script that starts at the top and queries for the next level of data. For each entry at that level, the recursion keeps drilling down until it reaches the bottom. There are several things to consider when setting up something like this. The most important one is where are you holding the data as you move between levels, etc. If you are not familiar with recursive programming, it can take a little getting used to.
Here is a simplistic version of a recursive function:
digDown : function(whatAccount, theData) {
var myTable = new GlideRecord("<your table name>);
myTable.addQuery("<account field>", whatAccount);
myTable.query();
while (myTable.next()) {
digDown(myTable.sys_id.toString, theData)
} else {
theData.push(myTavle.<identifier>.getDisplayValue());
return;
}
}
theData is an empty array that gets created before invoking the function. What will happen is that when it gets to the bottom of one leg of the hierarchy it will add that value to the array and go back to the next higher level where it will continue going through the rows selected until all have been done and them go back up a level. Of course you have some ohter options around how you store the data based on what else you need, etc.
:{)
Helpful and Correct tags are appreciated and help others to find information faster