- 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 11:18 AM
Thanks Amlan, that worked. I was not aware on reserved words but that is very helpful. If you have a moment to answer one more question....
I have three different server classes that an item could be ESX Server, Windows or Linux. If I follow the logic of the following script how do I add an else or if statement to into the other classes?
Thanks for all your help!
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();
}
else 'Linux server' or 'Windows Server'
- 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 01:30 PM
Alman,
Could you review my script? It's not creating the record. Thanks!
if(current.variables.server == 'ESX Server') {
var esx = new GlideRecord("cmdb_ci_esx_server");
esx.initialize();
esx.ip_address = current.variables.ip_address;
esx.name = current.variables.server_name;
esx.location = current.variables.location;
esx.insert();
}
else if(current.variables.server == 'Windows Server'){
var windows = new GlideRecord("cmdb_ci_windows_server");
windows.initialize();
windows.ip_address = current.variables.ip_address;
windows.name = current.variables.server_name;
windows.location = current.variables.location;
windows.insert();
}
else if(current.variables.server == 'Linux Server'){
var linux = new GlideRecord("cmdb_ci_linux_server");
linux.initialize();
linux.ip_address = current.variables.ip_address;
linux.name = current.variables.server_name;
linux.location = current.variables.location;
linux.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 06:29 PM
Hi Danielle,
The script looks fine. The only thing I doubt that, OOB there is no such table exists named 'cmdb_ci_windows_server'. Please verify the table name once. If I'm not wrong it should be 'cmdb_ci_win_server', which extends 'Server' table. Apart from that, the rest script seems good to go.
Did you try creating new record choosing the 'server; variable value as 'ESX Server' or 'Linux Server'? Are the choices of the 'server' variables same as 'ESX Server', 'Windows Server' and 'Linux Server'?