- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2017 03:44 PM
var gr=new GlideRecord('x_42426_automation_automation_rules');
gr.addQuery('automation_category','calculate_relationship');
gr.orderBy('order');
gr.query();
gs.addInfoMessage('test 1');
while(gr.next())
{
var attribute=gr.getValue('target_attribute');
var val=gr.getValue('target_value');
var query = gr.getValue('query_string');
gs.addInfoMessage('test 2');
var match=GlideFilter.checkRecord(current,query);
if (match)
{
var childT=current.name;
var manages='Managed by';
gs.addInfoMessage(val);
setRelationshipValues(val, childT, manages);
}
}
function setRelationshipValues(parent, child, relationshipType) {
gs.info("Relationship Insert attempt. parent(" + parent.sys_id + "), child(" + child.sys_id + "), relationship(" + relationshipType.sys_id + ")");
var rel_ci = new GlideRecord("cmdb_rel_ci");
rel_ci.initialize();
rel_ci.parent = parent.sys_id;
rel_ci.child = child.sys_id;
rel_ci.type = relationshipType.sys_id;
var sysId = rel_ci.insert();
}
I'm getting the error message as The recursive relationship ' :: ' is not allowed and has not been established
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2017 01:29 PM
var gr=new GlideRecord('x_42426_automation_automation_rules');
gr.addQuery('automation_category','calculate_relationship');
gr.orderBy('order');
gr.query();
while(gr.next())
{
var attribute=gr.getValue('target_attribute');
var val=gr.target_value;
var query = gr.getValue('query_string');
var match=GlideFilter.checkRecord(current,query);
if (match)
{
var childT=current.sys_id;
var manages='bf83653c0ab30150761028c73a4de0f4';
setRelationshipValues(val, childT, manages);
}
}
function setRelationshipValues(parent, child, relationshipType) {
// gs.addInfoMessage(parent);
// gs.addInfoMessage(child);
// gs.addInfoMessage(relationshipType);
if (parent == child)
return;
var rel_ci = new GlideRecord("cmdb_rel_ci");
rel_ci.initialize();
rel_ci.parent.setDisplayValue(parent);
rel_ci.child = child;
rel_ci.type = relationshipType;
rel_ci.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2017 03:56 PM
this thread might be helpful Can we have same CI names belonging to 2 different classes in CMDB? If yes, then how do we perform r...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2017 04:15 PM
I have modified the code to
var gr=new GlideRecord('x_42426_automation_automation_rules');
gr.addQuery('automation_category','calculate_relationship');
gr.orderBy('order');
gr.query();
gs.addInfoMessage('test 1');
while(gr.next())
{
var attribute=gr.getValue('target_attribute');
var val=gr.getValue('target_value');
var query = gr.getValue('query_string');
gs.addInfoMessage('test 2');
var match=GlideFilter.checkRecord(current,query);
if (match)
{
var childT=current.name;
var manages='Managed by';
gs.addInfoMessage(val);
setRelationshipValues(val, childT, manages);
}
}
function setRelationshipValues(parent, child, relationshipType) {
gs.addInfoMessage(parent);
gs.addInfoMessage(child);
gs.addInfoMessage(relationshipType);
var rel_ci = new GlideRecord("cmdb_rel_ci");
rel_ci.initialize();
rel_ci.parent = parent;
rel_ci.child = child;
rel_ci.type = relationshipType;
if(rel_ci.parent!=rel_ci.child)
{
rel_ci.insert(); }
}
Now its inserting empty record in 'cmdb_rel_ci' table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2017 01:29 PM
var gr=new GlideRecord('x_42426_automation_automation_rules');
gr.addQuery('automation_category','calculate_relationship');
gr.orderBy('order');
gr.query();
while(gr.next())
{
var attribute=gr.getValue('target_attribute');
var val=gr.target_value;
var query = gr.getValue('query_string');
var match=GlideFilter.checkRecord(current,query);
if (match)
{
var childT=current.sys_id;
var manages='bf83653c0ab30150761028c73a4de0f4';
setRelationshipValues(val, childT, manages);
}
}
function setRelationshipValues(parent, child, relationshipType) {
// gs.addInfoMessage(parent);
// gs.addInfoMessage(child);
// gs.addInfoMessage(relationshipType);
if (parent == child)
return;
var rel_ci = new GlideRecord("cmdb_rel_ci");
rel_ci.initialize();
rel_ci.parent.setDisplayValue(parent);
rel_ci.child = child;
rel_ci.type = relationshipType;
rel_ci.insert();
}