SSJS - Comma Separate Data from single Columns
Mon Jul 22 2024 17:17:08 GMT+0000 (Coordinated Universal Time)
Saved by
@Pradeep
<script runat="server">
Platform.Load("Core", "1");
// Define Data Extension Names
var sourceDEName = "Kp_Testing";
var targetDEName = "Processed_Products";
// Retrieve Source Data Extension
var sourceDE = DataExtension.Init(sourceDEName);
var rows = sourceDE.Rows.Retrieve();
// Retrieve Target Data Extension
var targetDE = DataExtension.Init(targetDEName);
// Loop through each row in the source Data Extension
for (var i = 0; i < rows.length; i++) {
var sKey = rows[i].SKey;
var productID = rows[i].ProductID;
// Split ProductID by comma
var productValues = productID.split(',');
// Loop through each product value and insert into the target Data Extension
for (var j = 0; j < productValues.length; j++) {
var productValue = productValues[j].trim(); // Trim whitespace
// Insert each product value into the target Data Extension
targetDE.Rows.Add({
SKey: sKey,
ProductValue: productValue
});
}
}
</script>
content_copyCOPY
Comments