- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 03:55 AM
Hi All,
There are CI A,B,C & D with below relationship.
I have to write a function in such a way that if I give ci D than function should return a result as array or all the ci (A,B,C,D).
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 04:20 AM
This SNGuru article is exactly what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 04:14 AM
Hi Pradeep,
getRelation(CIid , relationlength ) // relationLength mean how much dependence you want .. ex: 2 means parent's parent
function getRelation()
{
var relationShip = '';
for(var i=0;i<=relationLength ; i++)
{
relationShip += 'parent.';
}
Eg. if for length 2 it give value as parent.parent
var gr = new GlideRecord(TableName);
gr.addQuery('sys_id',CIID);
gr.query();
while(gr.next())
{
var CIrelatedTo2ndparent = gr.getValue(relationShip); // it gives you the Exact CI
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 04:20 AM
You will want to create a recursive lookup. So something like the below. I have not tested it and it all depend on what relationships you have set-up. I would also add in some data checking for infinite loops and ensure values are all set.
var finalArr = new Array();
getRelationships(current.sys_id);
function getRelationships(ci)
{
var []
//Loopup relationship table to see what it's dependant is.
var rel = new GlideRecord("");
rel.addQuery("parent",ci);
rel.addQuery("type", <<INSERT Relationship type here>>);
rel.query();
if(rel.next)
{
finalArr.push(rel.sys_id)
getRelationships(rel.sys_id);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 01:58 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 04:20 AM
This SNGuru article is exactly what you need.