Created
July 18, 2023 23:57
-
-
Save MyCueCards/f69e7c146c07d99487ee14ba1b31ac0d to your computer and use it in GitHub Desktop.
Populate with ampscript then run with ssjs activity. Create many data extensions with SSJS and ampscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// populate with ampscript | |
%%[ | |
/* Replace 'thisIsTheSourceDe' with the actual name of your data extension */ | |
var @dataExtensionName | |
set @dataExtensionName = "thisIsTheSourceDe" | |
/* Replace 'myCustomerKey' with the actual field name you want to populate */ | |
var @fieldName | |
set @fieldName = "myCustomerKey" | |
/* Retrieve all the records from the data extension */ | |
var @rows | |
set @rows = LookupRows(@dataExtensionName, "myCreatedDeName","1") | |
/* Check if there are any records found */ | |
var @rowCount | |
set @rowCount = RowCount(@rows) | |
/* If there are records found, loop through each record and display the value of the field */ | |
if @rowCount > 0 then | |
for @i = 1 to @rowCount do | |
var @row | |
set @row = Row(@rows, @i) | |
/* Replace 'fieldName' with the actual attribute name of your field */ | |
var @fieldValue | |
set @fieldValue = Field(@row, "myCustomerKey") | |
]%% | |
<p> | |
var deObj%%=v(@i)=%% = { <br> | |
CustomerKey: "%%=GUID()=%%",<br> | |
Name: "%%=v(@fieldValue)=%%",<br> | |
Fields: [<br> | |
{ "Name": "EmailAddress", "FieldType": "EmailAddress", "IsPrimaryKey": true, "IsRequired": true },<br> | |
{ "Name": "eventUniqueValue", "FieldType": "Text", "MaxLength": 30, "IsRequired": false },<br> | |
{ "Name": "campaignID", "FieldType": "Number", "IsRequired": false }<br> | |
],<br> | |
SendableInfo: {<br> | |
Field: { "Name": "EmailAddress", "FieldType": "EmailAddress" },<br> | |
RelatesOn: "Subscriber Key"<br> | |
},<br> | |
CategoryID: 789144<br> | |
};<br> | |
<br> | |
var de%%=v(@i)=%% = DataExtension.Add(deObj%%=v(@i)=%%); | |
<br> | |
</p> | |
%%[ | |
next @i | |
else | |
OutputLine("No records found in the data extension.") | |
endif | |
]%% | |
// copy result of ampscript. then place into ssjs | |
<script runat="server"> | |
Platform.Load("core", "1"); | |
// put ampscript result here | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment