- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 09:34 PM
Hello,
I am trying to load data, but after the transport map there's an error.
Can you please help to check my script there's an error variable is not defined.
Code:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 10:37 PM
it will ignore as you are adding that line at the end of code
Also are you sure this IF statement gave true? the only it will start the Cart API
if (managerExist.found == "true" && source.u_onboard_date!="") {
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 11:47 PM - edited 06-25-2023 11:47 PM
HI @Vengeful ,
I trust you are doing great.
Here's an updated version of your code with comments explaining the changes:
(function runTransformScript(source, map, log, target) {
// Add your code here
gs.log(
"Values = " +
source.u_shift + "\n" +
source.u_chinese_name + "\n" +
source.u_english_name + "\n" +
source.u_job_title + "\n" +
source.u_department + "\n" +
source.u_location + "\n" +
source.u_global_id__sf_id_ + "\n" +
source.u_remarks + "\n" +
source.u_start_date + "\n" +
source.u_name + "\n" +
source.u_first_name + "\n" +
source.u_given_name + "\n" +
source.u_employee_number + "\n" +
source.u_description
);
// Check if the manager, location, and department records exist
var managerExist = checkRecord(source.u_manager, "sys_user");
var locationExist = checkRecord(source.u_location, "cmn_location");
var departmentExist = checkRecord(source.u_department, "cmn_department");
gs.log("Manager found = " + JSON.stringify(managerExist));
// Check if the manager record exists and the source has an onboard date
if (managerExist.found === "true" && source.u_onboard_date !== "") {
var cart = new Cart();
var item = cart.addItem('e0fd19ce1b1be8d0efd69829bc4bcb41');
// Set variables for the cart item
cart.setVariable(item, 'shift', source.u_shift);
cart.setVariable(item, 'chinese_name', source.u_local_language_name);
cart.setVariable(item, 'english_name', source.u_english_name);
cart.setVariable(item, 'manager', managerExist.name);
cart.setVariable(item, 'job_title', source.u_job_title);
cart.setVariable(item, 'department', departmentExist.name);
cart.setVariable(item, 'pc_deployment', source.u_pc_deployment);
cart.setVariable(item, 'location', locationExist.name);
cart.setVariable(item, 'ocn', source.u_global_id__sf_id_);
cart.setVariable(item, 'remarks', source.u_remarks);
cart.setVariable(item, 'start_date', source.u_start_date);
cart.setVariable(item, 'name', source.u_name);
cart.setVariable(item, 'first_name', source.u_first_name);
cart.setVariable(item, 'given_name', source.u_given_name);
cart.setVariable(item, 'employee_number', source.u_employee_number);
cart.setVariable(item, 'description', source.u_description);
cart.setVariable(item, 'created_by_excel', "true");
// Place the order and retrieve the request
var rc = cart.placeOrder();
gs.log("Request = " + rc.number);
var gr = new GlideRecord("sc_req_item");
if (gr.get("request", rc.sys_id)) {
gs.log("RITM = " + gr.number);
gr.short_description = gr.short_description + " - " + gr.getDisplayValue("opened_by.country");
gr.update();
}
}
// Function to check if a record exists in a table
function checkRecord(name, table) {
var record = {};
record.name = "";
record.found = "false";
gs.log("Checking user " + name);
var gr = new GlideRecord(table);
if (gr.get("name", name) && name !== "") {
record.found = "true";
record.name = gr.getValue("sys_id");
}
return record;
}
ignore = true;
})(source, map, log, target);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 10:06 PM
script looks fine to me
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 10:33 PM
The transform is success, but its not created RITM.
When I checked the transform history, there's 1 ignored which is this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 10:37 PM
it will ignore as you are adding that line at the end of code
Also are you sure this IF statement gave true? the only it will start the Cart API
if (managerExist.found == "true" && source.u_onboard_date!="") {
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 10:56 PM
Hi Ankur,
Actually that script is working in our prod instance.
However, after I added new variables: name, first_name, given_name, employee_number and description, it's no longer working. I mean no RITM is created.