0

I have tried to use DataExtension.Init() several times with no avail. I can see the Data extension in both parent and child business Unit (it lives in the shared data extension folder). I've also tried a newly created data extension. I keep getting null objects returned even after verifying the DE exists using

var FindDE = DataExtension.Retrieve({Property:DEprop,SimpleOperator:"equals",Value:DEval});
   Write("FindDE: " + Stringify(FindDE));

I have tried external Key and name and I can't get it to work. Current code below, any help welcomed!


    <script runat="server">
Platform.Load("core","1.1.1");  



try {
// Initialize the existing Data Extension
var DEprop = "Name"
var DEval = "Products_Catalog"
var FindDE = DataExtension.Retrieve({Property:DEprop,SimpleOperator:"equals",Value:DEval});
   Write("FindDE: " + Stringify(FindDE));
  var sourceDE = DataExtension.Init(FindDE[0].CustomerKey);
  Write(sourceDE["CustomerKey"]);
  Write(sourceDE);
  

  
} catch (e) {
    // Log error message
    Write("Error: " + Stringify(e));
}


</script>

1 Answer 1

0

Shared Data Extensions are technically located in Parent, meaning you definitely need to be running your script in Parent BU to work.

You can find out where it's running using

var parentBU = Platform.Function.AuthenticatedEnterpriseID()

var mycurrentBU = Platform.Function.AuthenticatedMemberID()

and outputting those vars.

I can confirm that DataExtension.Init works on customer key, but really in 99.9% I would just not bother with the whole syntax associated. Switch to WSProxy, where you can simply retrieve by name.

Instead of trying to get a key by name, then initialize the key, then parse, then proceed on the result. All of these little things tend to take longer than expected and I have found to just skip them makes life a lot easier.

You initialize WSproxy like so

var api = new Script.Util.WSProxy();

and then run scripts like here.

var cols = [
    "ObjectID",
    "PartnerKey",
    "CustomerKey",
    "Name",
    "CreatedDate",
    "ModifiedDate",
    "Client.ID",
    "Description",
    "IsSendable",
    "IsTestable",
    "SendableDataExtensionField.Name",
    "SendableSubscriberField.Name",
    "Template.CustomerKey",
    "CategoryID",
    "Status",
    "IsPlatformObject",
    "DataRetentionPeriodLength",
    "DataRetentionPeriodUnitOfMeasure",
    "RowBasedRetention",
    "ResetRetentionPeriodOnImport",
    "DeleteAtEndOfRetentionPeriod",
    "RetainUntil",
    "DataRetentionPeriod"
];

var result = api.retrieve("DataExtension", cols, {
    Property: "Name",
    SimpleOperator: "equals",
    Value: "MyDataExtension"
});

https://www.ssjsdocs.xyz/contact-builder/dataextensions/retrieve/

sidenote

WSProxy also comes with the handy "QueryAllAccounts" option which is documented here https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_WSProxy_advanced_retrieve.html

2
  • Thanks for your answer Jonas, That was the route I took after running into so many setbacks. I was attempting to use this to create a csv to send to FTP but there doesn't seem to be a way to use ssjs or wsproxy to send to my enhanced FTP @Jonas
    – A S
    Commented Jun 4 at 13:20
  • Interaction with sftp works via data extract / file import only, not directly via SSJS. You'll have to investigate ways to create extracts etc with SSJS, which is supported. But that's for another question ;) Commented Jun 4 at 16:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .