Scripting in the Transform Map to Map Field

Vamsi26
Tera Contributor

Hello Everyone,

I want to set the Delivery time with the value of the Catalog Item If import set row column is empty on the sheet.

Excel Sheet:

Vamsi26_0-1688566989727.png

Table: 

Vamsi26_1-1688567214106.png

 

Transform Map:

Vamsi26_2-1688567276279.png

 

What needs to be done further to achieve "to set the Delivery time with the value of the Catalog Item If import set row column is empty ???"

 

Thanks

Not applicable

Hello @Vamsi26 ,

 

To set the Delivery time in the target table(u_catalog_refference) if it is empty in the source table(table created after importing the Excel file) you can use a transform map script, you can follow these steps:

  1. Open the Transform Map associated with the import.
  2. Go to the Transform Scripts-related list.
  3. Click on --New-- button.
  4. Create the "OnBefore" script, and enter the following script:

 

(function(source, map, log, target) {
  if (JSUtil.nil(source.getValue('u_delivery_time'))) {
    target.u_delivery_time = "2 day"; // set value here
  }
})(source, map, log, target);

 


Now, when you import an Excel file and map the Delivery time field, the script in the Transform Map will check if the Delivery time is empty in the source table. If it is empty, it will set the value which you configure in the script.

Note: Make sure to adjust the field names (u_delivery_time and target) in the code according to your actual field names in the transform map and target table.

Hit the like button if this helps you in any way. So, that it will help others to find the correct solution!

 

regards,

Prasad

Hello @Community Alums 

The scripting is setting "2 days" for all the records. There are items with different days 1 day, 3days , 5days. 

How to check the conditions of Catalog item "delivery_time" ?? 

 

Vamsi26_1-1688571883095.png

 

Script:

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (JSUtil.nil(source.getValue('delivery_time'))) {
        target.u_delivery_time = "2 days"; // set value here
    }

})(source, map, log, target);

 

 

 Thanks

Not applicable

@Vamsi26 ,

If I got you correctly, you want to set the value of delivery time on the basis of the Catalog item.

If yes,

For e.g., If the Catalog item is 'Software' then the Delivery time should be '2 days',

If the Catalog item is 'Hardware' then the Delivery time should be '3 days' and so on.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (JSUtil.nil(source.getValue('delivery_time'))) {
        if (source.catalog_item == 'Software') {
            target.u_delivery_time = "2 days"; // set value here
        } else if (source.catalog_item == 'Hardware') {
            target.u_delivery_time = "3 days"; // set value here
        } else {
            target.u_delivery_time = "4 days"; // set value here
        }
    }

})(source, map, log, target);

 

Note: You can use a switch case for the above scenario. This might help you: How to use a switch case?

 

If No,

Please correct me!

 

thanks,

Prasad

@Community Alums 

If the Excel sheet Delivery time is Empty then it should check the "Delivery Time from the Catalog item"  and set the Target value on the table.

Vamsi26_0-1688628668038.png

 

I written the script like this but it's not working.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (JSUtil.nil(source.getValue('delivery_time') == "02 00:00:00")) {
        target.u_delivery_time = "2 days"; // set value here
    } else if(JSUtil.nil(source.getValue('delivery_time') == "03 00:00:00")) {
        target.u_delivery_time = "3 days"; // set value here
    }

})(source, map, log, target);

 Thanks