Create a appliction CI via runscript

Selva Arun
Mega Sage
Mega Sage

HI, I have created a techincal catalog for automating the application CI creation via run script, but the records are not being inserted. Can anyone check the below code and let me know what is wrong:

 

var applicationName=current.variables.application_name;
var applicationVersion= current.variables.version;
var applicationDescription= current.variables.description;
var applicationClass=current.variables.class;
var applicationSubCat= current.variables.Subcategory;
var applicationCat= current.variables.category;

var gr = new GlideRecord('cmdb_ci_appl');
gr.setValue('name', applicationName);
gr.setValue('version',applicationVersion);
gr.setValue('short_description',applicationDescription);
gr.setValue('sys_class_name', applicationClass);
gr.setValue('subcategory', applicationSubCat);
gr.setValue('category', applicationCat);
gr.setValue('support_group', current.variables.support_group.sys_id);
gr.setValue('vendor', current.variables.vendor.sys_id);
gr.insert();

Also, I want to know how I can add the newly created CI link to the notification message body for informing the requestor after CI creation and I want to know how I can sys_class_name field to the catalog item variable without having to create 243 choices for this field.

Thank you

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

Perhaps the script dies on line

var applicationClass = current.variables.class;

class being a reserved word.

 

Also what would it cost you to hit the Format tool button in the SN code editor from time to time?

View solution in original post

2 REPLIES 2

-O-
Kilo Patron
Kilo Patron

Perhaps the script dies on line

var applicationClass = current.variables.class;

class being a reserved word.

 

Also what would it cost you to hit the Format tool button in the SN code editor from time to time?

Yes please, thank you! I fixed it yesterday after seeing this error:

// Run script for creating the CI
var applicationName=current.variables.application_name;
var applicationVersion= current.variables.version;
var applicationDescription= current.variables.description;
var applicationClass=current.variables.application_class;
var applicationSubCat= current.variables.Subcategory;
var applicationCat= current.variables.category;
var applicationSgroup= current.variables.support_group;
var applicationVendor= current.variables.vendor;
var gr = new GlideRecord('cmdb_ci_appl');
gr.initialize();
gr.name= applicationName;
gr.version=applicationVersion;
gr.short_description= applicationDescription;
gr.sys_class_name = applicationClass;
gr.subcategory= applicationSubCat;
gr.category= applicationCat;
gr.support_group= applicationSgroup;
gr.vendor= applicationVendor;
gr.insert();