Auto creation - update/create

Vaibhav Ramteke
Giga Contributor

Hello,

Auto application creation in Application Table if any new application is created in Business Application table

Im trying to run above using business rule but its not working properly whenever i do the changes in business appl. change happen in application but also create new few field only update not overall which i want.

cmdb_ci_business_appl -> cmdb_ci_appl

Thank you

1 ACCEPTED SOLUTION

rohansargar
Mega Guru

hi @Vaibhav Ramteke ,
try this

 

Table: cmdb_ci_business_appl

when: After
Inster and Update check box true.

 

Code : 

(function executeRule(current, previous /*null when async*/) {

var appGR = new GlideRecord('cmdb_ci_appl');

// Check if related application already exists
// Use correlation field or unique identifier
appGR.addQuery('name', current.name);
appGR.query();

if (appGR.next()) {

// UPDATE existing record
appGR.name = current.name;
appGR.short_description = current.short_description;
appGR.description = current.description;
appGR.install_status = current.install_status;
appGR.business_criticality = current.business_criticality;
appGR.owned_by = current.owned_by;
appGR.support_group = current.support_group;
appGR.location = current.location;

// Add more fields as needed
appGR.update();

} else {

// CREATE new record
appGR.initialize();
appGR.name = current.name;
appGR.short_description = current.short_description;
appGR.description = current.description;
appGR.install_status = current.install_status;
appGR.business_criticality = current.business_criticality;
appGR.owned_by = current.owned_by;
appGR.support_group = current.support_group;
appGR.location = current.location;

// Reference to business app if field exists
// appGR.u_business_application = current.sys_id;

appGR.insert();
}

})(current, previous);

 

 

if my response helped please mark it as helpful or accept as solution.

View solution in original post

2 REPLIES 2

rohansargar
Mega Guru

hi @Vaibhav Ramteke ,
try this

 

Table: cmdb_ci_business_appl

when: After
Inster and Update check box true.

 

Code : 

(function executeRule(current, previous /*null when async*/) {

var appGR = new GlideRecord('cmdb_ci_appl');

// Check if related application already exists
// Use correlation field or unique identifier
appGR.addQuery('name', current.name);
appGR.query();

if (appGR.next()) {

// UPDATE existing record
appGR.name = current.name;
appGR.short_description = current.short_description;
appGR.description = current.description;
appGR.install_status = current.install_status;
appGR.business_criticality = current.business_criticality;
appGR.owned_by = current.owned_by;
appGR.support_group = current.support_group;
appGR.location = current.location;

// Add more fields as needed
appGR.update();

} else {

// CREATE new record
appGR.initialize();
appGR.name = current.name;
appGR.short_description = current.short_description;
appGR.description = current.description;
appGR.install_status = current.install_status;
appGR.business_criticality = current.business_criticality;
appGR.owned_by = current.owned_by;
appGR.support_group = current.support_group;
appGR.location = current.location;

// Reference to business app if field exists
// appGR.u_business_application = current.sys_id;

appGR.insert();
}

})(current, previous);

 

 

if my response helped please mark it as helpful or accept as solution.

Vaibhav Ramteke
Giga Contributor

in this code use as same as per my naming condition update is working but when i create new one in cmdb_ci_business_app then no new creation in cmdb_ci_appl