Unable to fetch values from variables of a catalog task into a RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 08:50 PM
Hello Team,
I am able to relate a new RITM in an existing request through a UI action. However I am unable to get the values like assignment group; & short description to be populated into the RITM. What may be the reason The code is as follows, the entire process is working through a UI action (involving insert of variable data etc.). can someone advise asap?
//Creating the RITM
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, '0728b2051ba60014334efc031d4bcb61', 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);
// Update the variables in the created RITM
var createRITM = new GlideRecord("sc_req_item");
createRITM.initialize();
createRITM.assignment_group = current.assignment_group;
createRITM.short_description = "Discovery on demand – " + current.variables.ip_address;
Regards
Nilanjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 10:13 AM
try {
var reqHelper = new GlideappRequestHelper();
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = current.request;
ritm.cat_item = '0728b2051ba60014334efc031d4bcb61';
ritm.u_requested_for = current.u_requested_for;
ritm.assignment_group = current.assignment_group;
ritm.short_description = 'Discovery on demand - ' + current.variables.ip_address;
ritm.insert();
reqHelper.addRequestItem(current.request, ritm.sys_id);
reqHelper.rebalanceRequest(current.request);
var serverTableName = current.variables.sys_class_name;
var grServer = new GlideRecord(serverTableName);
grServer.initialize();
grServer.name = current.variables.name;
grServer.location = current.variables.location;
grServer.operational_status = current.variables.operational_status;
grServer.install_status = current.variables.status;
grServer.sys_class_name = current.variables.sys_class_name;
grServer.u_billable_2 = current.variables.billable;
grServer.u_device_type = current.variables.billable_device_type;
grServer.install_date = current.variables.installed_date;
grServer.u_vendor_managed_1 = current.variables.vendor_managed;
grServer.vendor = current.variables.vendor;
grServer.ip_address = current.variables.ip_address;
grServer.u_reboot_notes = current.variables.reboot_notes;
grServer.maintenance_schedule = current.variables.maintenance_schedule;
grServer.used_for = current.variables.used_for;
grServer.os = current.variables.operating_system;
grServer.environment = current.variables.environment;
grServer.dns_domain = current.variables.dns_domain;
grServer.virtual = current.variables.is_virtual;
grServer.short_description = current.variables.description;
grServer.insert();
} catch (e) {
gs.error(e);
throw e;
}
The script I provided is an example of how you can add error handling to your existing script. However, there might be some issues with the script if the field names, variable names, and table names in the script do not match the actual names used in your environment.
Also, the script assumes that you have the necessary permissions to insert and update records in the "sc_req_item" table and the CMDB table specified in the serverTableName variable.
Additionally, it assumes that you have GlideappRequestHelper class and GlideappCalculationHelper class available in your instance, if these classes are not available in your instance, you'll get an error when trying to use them.
It's recommended to test the script on a non-production instance before deploying it to production, and make any necessary adjustments to the script based on the results of your testing.
Please let me know if you have any other question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2023 08:53 AM
Hello Mohammed,
Thank you for the reply, when I am using the glidehelper API it is attaching the exact request item that I am looking to, however the only thing that I am left gaping is on the two variable.
1. Assignment group
2. Short description which is being populated from the variables that is set in the sc task.
Having said that if I am not using the helper function.. the new ritm is getting attached
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2023 09:55 AM
The two variables that you are having trouble with, "assignment_group" and "short_description," are being set from the "current" object, which is likely a GlideRecord or GlideScriptRecord object, and the "variables" object, which is likely a GlideScriptRecord object. It is unclear from this code snippet what the values of these variables are, or where they are being set.
It sounds like you have an issue with the variable "short_description" which is being populated from the variable that is set in the sc task. The variable "assignment_group" is also being set but it's not clear what the source is. You could check the values of these variables in the sc_task record and also check the type of the current object, if it is GlideRecord or GlideScriptRecord.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 11:56 AM
Your script is trying to create two different Request Items. addItemToExistingRequest() is going to order the catalog item with the sys_id provided. That probably isn't working unless that item has no variables...you need to set the variable values manually. Next you have CreateRITM GlideRecord that doesn't call insert() or update(). If that just isn't shown here you're also not setting the Request field on the New RITM so it won't be related to the current Request. Are you sure you're not making it more difficult than you need to?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2023 09:41 AM
Thank you Ricker. with the newGlideAddHelper() method. I am able to relate the correct RITM to the request which is one of the requirement. However I am unable to get the variables such as the assignment group and the short description through the following script - where I want to reach. Hope I am not confusing you 🙂
ritm.assignment_group = current.assignment_group;
ritm.short_description = 'Discovery on demand - ' + current.variables.ip_address;