- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 08:15 AM
Scripting isn't my strong suit and I'm sure it's an easy fix but I can't get it. I need to crate a record on the cmdb_ci_server table from within a workflow. I can get the record to create but it's not inputting the values from the variables. Instead it is just inputting what is between the ' ' or for the value of sys_class_name is is just inputting 'server' instead of ESX Server.
Any help would be great! Thanks!
var server = new GlideRecord("cmdb_ci_server");
server.initialize();
server.setValue('ip_address','current.variables.ip_address');
server.setValue('name', 'current.variables.server_name');
server.setValue('sys_class_name', 'current.variables.class');
server.insert();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 11:50 AM
Hi Danielle,
I'm Glad that it helped you. If i have answered your question, would you mind marking the Answer Correct and close the thread?
In this case, you can use the below script:
if(current.variables.class == 'ESX Server') {
var server = new GlideRecord("cmdb_ci_esx_server");
server.initialize();
server.ip_address = current.variables.ip_address;
server.name = current.variables.server_name;
server.sys_class_name = current.variables.class;
server.insert();
}
else if(current.variables.class == 'Windows'){
//Do your logic
//You can follow the first If() loop
}
else if(current.variables.class == 'Linux'){
//Do your logic
//You can follow the first If() loop
}
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 08:53 AM
The field sys_class_name is an oob field that references the cmdb classes. What I'm needing to accomplish with this field is for the record to create in the correct CI class (i.e. ESX Server, Windows Server, Linux Server).
For testing my code is simply:
var server = new GlideRecord("cmdb_ci_server");
server.initialize();
server.setValue('ip_address',current.variables.ip_address);
server.setValue('name', current.variables.server_name);
server.setValue('sys_class_name', current.variables.class);
server.insert();
screenshot of error in workflow:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 08:55 AM
Should the code include logic instead that says if variable class is ESX Server then create record in cmdb_ci_esx_server instead?? That is a little advanced for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 09:13 AM
Hi Danielle,
Yes, you can incorporate this logic also. I've modified your code a bit incorporating the above. Could you please give it a try?
if(current.variables.class == 'ESX Server') { //This will check whether the provided Class is 'ESX Server' or not
var server = new GlideRecord("cmdb_ci_esx_server");
server.initialize();
server.ip_address = current.variables.ip_address;
server.name = current.variables.server_name;
server.sys_class_name = current.variables.class;
server.insert();
}
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 10:40 AM
unfortunately that did not work. I now receive the following error:
SyntaxError: missing name after . operator (#0(eval); line 1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 10:53 AM
Hi Danielle,
My bad, in order noticing the issue earlier. The error is coming because of the 'class', which is a reserved word. You can find the list of reserved words here: JavaScript Reserved Words . To my best knowledge, as part of solution, you need to change the variable name to something else which is not reserved word. Once you are done with this, please modify the script accordingly and try again.
For reference you can refer this helpful thread: missing name after . operator
I hope this helps. Please mark correct/helpful based on impact