importing data and Transforming variables to the newly created ritms
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 11:36 AM
I am trying to create bulk RITMs using data from excel spreadsheet. Most of the information is put in a form then we submit the form and the variables shows up on the bottom of the RITM(see screenshot of list of some variables) so most of these variables do not have a field to transform to.
How do I go about adding the bulk RITMs and have the variable also show on the bottom of the RITM.
I found a script I thought might help and put my information in for one variable sys id. No luck and really not sure if this is the correct way.
var grVar = new GlideRecord('sc_item_option');
grVar.initialize();
grVar.request_item = target.sys_id; // Link to request
grVar.item_option_new = '9be91847db58270072a46693ca961948'; // Corrected sys_id format
grVar.value = source.ProperName; // Ensure this matches your Excel column name
grVar.insert();
Can I get some help on how to accomplish loading the data and having the variables transformed to the bottom of created RITMs.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 12:12 PM - edited 03-11-2025 12:15 PM
Hi @scotte,
You can set the variables on your RITM (GlideRecord("sc_req_item")) as follow:
grRITM.variables.VARIABLE_TECHNICAL_NAME = source.YOUR_SOURCE_FIELD;
If your transform map is having sc_req_item as a target table. You can try this on an onBefore script:
target.variables.VARIABLE_TECHNICAL_NAME = source.YOUR_SOURCE_FIELD;
I have just tried:
Result:
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 10:13 AM
Ok so I put in an on before script when transforming. But am getting an error 'Failed to insert variable: ........
Not sure what I am missing in the script. Here is the script. Any ideas
(function transformEntry(source, target, map, log, isUpdate) {
var requestID = source.request;
// If no request is linked, create a new one
if (!requestID) {
var request = new GlideRecord('sc_request');
request.initialize();
request.requested_for = source.requested_for || gs.getUserID();
request.short_description = "Bulk Request";
requestID = request.insert();
log.info('Created Request: ' + requestID);
}
// Create the RITM
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.cat_item = '53895c8bdb58270072a46693ca961910';
ritm.request = requestID;
ritm.quantity = 1;
ritm.short_description = source.short_description || 'Bulk RITM Creation';
var ritmID = ritm.insert();
log.info('Created RITM: ' + ritmID);
// Attach variables to RITM
if (ritmID) {
var variables = {
'hire_type': source.HireType,
'proper_name': source.ProperName,
'alt_name': source.AlternateName,
'employee_id': source.EmployeeID,
'empl_dept': source.EmployeeDepartment,
'manager': source.EmployeeManager,
'HRBP_name': source.HRBPName,
'start_date': source.StartDate,
'cmdb_ci': source.ConfigItem,
'network_login': source.NetworkLogin
};
for (var varName in variables) {
var varValue = variables[varName];
var variableSysID = getVariableSysID(varName);
if (varValue && variableSysID) {
var grVarMtom = new GlideRecord('sc_item_option_mtom');
grVarMtom.initialize();
grVarMtom.request_item = ritmID; // Link to RITM
grVarMtom.item_option_new = variableSysID; // Link to Variable
grVarMtom.value = varValue; // Set Value
grVarMtom.insert();
log.info('Added variable ' + varName + ' with value: ' + varValue);
} else {
log.error('Failed to insert variable: ' + varName + ' - Check variable name in Service Catalog');
}
}
}
// Function to get the sys_id of the variable definition
function getVariableSysID(varName) {
var grVarDef = new GlideRecord('item_option_new');
grVarDef.addQuery('name', varName);
grVarDef.query();
if (grVarDef.next()) {
log.info('Variable ' + varName + ' sys_id: ' + grVarDef.sys_id);
return grVarDef.sys_id;
}
log.error('Variable ' + varName + ' not found');
return null;
}
})(source, target, map, log, action === 'update');