Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: Service Stack Application Lookup
- When: after
- Insert: true
- Update: true
- */
- //Lookup stack applications
- var stackApp = new GlideRecord('u_service_stack_application');
- stackApp.addQuery('u_search_table', current.sys_class_name);
- stackApp.query();
- while(stackApp.next()) {
- if(eval('current.' + stackApp.u_search_field) == stackApp.u_search_text) {
- createRelationship();
- }
- }
- function createRelationship() {
- var app = new GlideRecord(current.sys_class_name);
- app.addQuery('sys_id', current.sys_id);
- app.addQuery(stackApp.u_conditions);
- app.query();
- if(app.next()) {
- var rel1 = new GlideRecord('cmdb_rel_ci');//check for existing relationships
- rel1.addQuery('parent.sys_id', stackApp.u_service_stack.sys_id);
- rel1.addQuery('child.sys_id', app.sys_id);
- rel1.query();
- if(!rel1.next()) {
- gs.addInfoMessage('Creating Relationship for ' + app.name);
- var newRel = new GlideRecord('cmdb_rel_ci');//create relationship
- newRel.initalize();
- newRel.parent = stackApp.u_service_stack.sys_id;
- newRel.child = app.sys_id;
- newRel.type = stackApp.u_relationship_type;
- newRel.insert();
- //if Service Stack Application specifies parent field, create additional relationship
- if(!stackApp.u_parent_ci_field.nil()){
- var rel2 = new GlideRecord('cmdb_rel_ci');//check for existing relationships
- rel2.addQuery('parent.sys_id', app.sys_id);
- rel2.addQuery('child.sys_id', stackApp.u_parent_ci_field.sys_id);
- rel2.query();
- if(!rel2.next()) {
- var newParentRel = new GlideRecord('cmdb_rel_ci');//create relationship with specified type
- newParentRel.initalize();
- newParentRel.parent = app.sys_id;
- newParentRel.child = eval('app.' + stackApp.u_parent_ci_field).sys_id;;
- newParentRel.type = stackApp.u_relationship_type;
- newParentRel.insert();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment