- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 09:02 PM
I am trying to map a field from a data source through a transform script, but I keep getting an error after I run the transform. Any idea what could be wrong here?
I want to map the additional_field (datasource) to the "additional" variable.
When:onBefore
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var cart = new Cart();
//Catalog Item sys_id
var item = cart.addItem('10a2f5dfc6112276018db58138c7a1e0');
//set variables
var dataSource = source.additional_test;
cart.setVariable(item, 'additional', dataSource);
var rc = cart.placeOrder();
})(source, map, log, target);
Screenshot of test data source
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 05:40 PM
Finally I figured it out after spending sometime on this.
Basically to create a cart for a specific user I.e set opened_by field you need to place this line above var cart = new Cart(); in your code.
var openedBy = new GlideRecord("sys_user");
openedBy.addQuery("email", source.u_opened_by_work_email);
openedBy.query();
if (openedBy.next()) {
var openedBy = openedBy.sys_id;
}
Now modify the line var cart = new Cart(); as var cart = new Cart(null, openedBy); //This will set the openedBy field on item table.
I think you can also GlideRecord the item table and set the field. I haven't tried that option as of now. Will keep you posted.
P.S : Community is currently down. Will modify your code and update on community once it is up and running.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 03:33 PM
Hi pradeep, no luck still on setting the requested for on the catalog item variable. Here is my entire script as is:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var cart = new Cart();
//Catalog Item sys_id
var item = cart.addItem('10a2f5dfc6112276018db58138c7a1e0');
//set variables
var dataSource = source.u_additional_test;
cart.setVariable(item, 'additional', dataSource);
ignore = true;
// set the requested for
var gr = new GlideRecord("sys_user");
gr.addQuery("user_name", source.u_requested_for);
gr.query();
if (gr.next()) {
var cartGR = cart.getCart();
cartGR.requested_for = gr.sys_id;
cartGR.requested_by = gr.sys_id;
cartGR.manager = gr.manager;
var setVariable = gr.sys_id;
cartGR.update();
}
var gr = new GlideRecord("sys_user");
gr.addQuery("user_name", source.u_requested_for);
gr.query();
if (gr.next()) {
var cart = new Cart();
cart.setVariable('item', 'user_name_test', gr.sys_id);
}
var rc = cart.placeOrder();
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 03:47 PM
Modified code:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gr = new GlideRecord("sys_user");
gr.addQuery("user_name", source.u_requested_for);
gr.query();
if (gr.next()) {
createItem(gr);
}
function createItem(gr)
{
var cart = new Cart();
//Catalog Item sys_id
var item = cart.addItem('10a2f5dfc6112276018db58138c7a1e0');
//set variables
var dataSource = source.u_additional_test;
cart.setVariable(item, 'additional', dataSource);
cart.setVariable('item', 'user_name_test', gr.sys_id);
var rc = cart.placeOrder();
// set the requested for
var cartGR = cart.getCart();
cartGR.requested_for = gr.sys_id;
cartGR.requested_by = gr.sys_id;
cartGR.manager = gr.manager;
var setVariable = gr.sys_id;
cartGR.update();
}
}
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 04:00 PM
Line 18 expects a sc_cart_item sys_id not a text string of 'item'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 04:08 PM
no luck, none of the variables were set after running that.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 04:43 PM
Can you paste the below code after line no 8 and try once.
else (
createItem(gr);
}
NOTE: The above code is just for testing purpose.