- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-13-2019 06:11 PM
Hi everyone,
What i need to do is stop creating assets for those ci's who has the field "Is Virtual" filled this field is on the server classes.
for this I update this 'OOB' Before Business Rule "Create Asset on Insert"
1.var ca = new AssetandCI();
2.var table = current.sys_class_name;
3.if(table.indexOf("server") >=0){
4.gs.log('Name of the CI: ' + current.name);
5.gs.log('Virtual Value: ' + current.ref_cmdb_ci_server.virtual);
6.if(!current.ref_cmdb_ci_server.virtual){
7.ca.createAsset(current);
8.}else{
9.}
10.}else{
11.ca.createAsset(current);
12.}
But isn't working, because this business rule runs on 'before' and when i create the CI with the "Is Virtual" field filled this shows as false on the business rule and dont run properly, this is an example:
This is the CI created:
This is the Log from the business rule
note that the field 'Is Virtual' is filled and the log validation for that field response as false.
I know if I change the Business rule to 'after' it will run properly but when the result must be the creation of the Asset that didn't happen because there is a script include that needs to be changed i think but don't whant to because there are a lot of scripting 'OOB' and update that can break something else.
Anyone has an idea about how to do this?.
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-13-2019 09:12 PM
Hi,
Your script doesn't address the relevant record's 'Is Virtual' so it will fail. I've modified with a comment below, and tested functionality in my personal dev
var ca = new AssetandCI();
var table = current.sys_class_name;
if(table.indexOf("server") >=0){
gs.log('Name of the CI: ' + current.name);
gs.log('Virtual Value: ' + current.virtual); // ref_cmdb_ci_server is not req
if(!current.virtual){ // current.virtual addresses the inserted record's virtual tag regardless of table extension
ca.createAsset(current);
}
else{
}
}
else{
ca.createAsset(current);
}
The 'Is Virtual' flag is also set by a 'Before' business rule with order 100, so you need to be careful to maintain the current order.
An alternative, is to consider that the Asset insert functionality is driven by Model Categories, and a possible option would be to toggle 'Enforce CI Verification' to true, and then have an 'After' Business Rule that triggers on Insert when 'Is Virtual' is false to create an asset.
Hope one of these resolves your concern.
Kind Regards,
Astrid

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-13-2019 09:12 PM
Hi,
Your script doesn't address the relevant record's 'Is Virtual' so it will fail. I've modified with a comment below, and tested functionality in my personal dev
var ca = new AssetandCI();
var table = current.sys_class_name;
if(table.indexOf("server") >=0){
gs.log('Name of the CI: ' + current.name);
gs.log('Virtual Value: ' + current.virtual); // ref_cmdb_ci_server is not req
if(!current.virtual){ // current.virtual addresses the inserted record's virtual tag regardless of table extension
ca.createAsset(current);
}
else{
}
}
else{
ca.createAsset(current);
}
The 'Is Virtual' flag is also set by a 'Before' business rule with order 100, so you need to be careful to maintain the current order.
An alternative, is to consider that the Asset insert functionality is driven by Model Categories, and a possible option would be to toggle 'Enforce CI Verification' to true, and then have an 'After' Business Rule that triggers on Insert when 'Is Virtual' is false to create an asset.
Hope one of these resolves your concern.
Kind Regards,
Astrid