Scripting to Map a Field in Transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2023 08:07 AM
I have 2 fields on table build a transform map to load the data into table.
I want to map the "Service" Field using script.
Can you please help me on this:
If the Service is not empty, map each value of the Excel with the right Service to Target.
I wrote the below script which is not working
answer = (function transformEntry(source) {
if (target.u_delivery_time.nil()) {
target.u_delivery_time = source.u_delivery_time;
}
})(source);Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2023 10:07 AM
Hello @Vamsi43 ,
I think you need to return the value in you script, because you don't have access to the target object. Here what you script need to look like:
answer = (function transformEntry(source) {
if (target.u_delivery_time.nil()) {
return source.u_delivery_time;
}
})(source);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 09:47 AM
Hello @MahaAgineo
I want to check both the conditions on the script
1. If the Service is not empty, map each value of the Excel with the right Service to Target.
2. If Service is empty, then set the Delivery time with the value of the Catalog Item.
I wrote the below script which is not working.
answer = (function transformEntry(source) {
if (target.u_delivery_time.nil()) {
var delivery;
var catalogItemGR = new GlidRecord("sc_cat_item");
catalogItemGR.addNullQuery('delivery_time');
catalogItemGR.query();
while (catalogItemGR.next()) {
delivery = source.delivery_time;
}
return delivery; // return the value to be put into the target field
} else {
return source.u_delivery_time;
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 01:00 AM - edited 07-05-2023 01:02 AM
Hello @Vamsi43,
You don't have access to the target object, so you need to use a transform map script (set run Script to true see Screenshot), and use this code:
(function transformRow(source, target, map, log, isUpdate) {
if (target.u_delivery_time.nil()) {
var delivery;
var catalogItemGR = new GlidRecord("sc_cat_item");
catalogItemGR.addNullQuery('delivery_time');
catalogItemGR.query();
while (catalogItemGR.next()) {
delivery = source.delivery_time;
}
target.u_delivery_time = delivery; // return the value to be put into the target field
} else {
target.u_delivery_time = source.u_delivery_time;
}
})(source, target, map, log, action === "update");
And I don't think you need the else because the field will be by default mapped to the source, with the normal field field mapping (without script)
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 02:26 AM
Then what about the Field Maps script i need erase it all and map direct like this?