1

I'm using a landing page with some SSJS to create several shortcut utilities for Marketing Cloud - namely copying data extensions and running single-use queries without having to save them. I've got a form which copies data extensions when you specify which one you want to copy. Users type the name in the box and press submit.

My one problem is that it's using the Data Extension Customer Key to look it up rather than the name. Unfortunately most of are users are only going to know the name and not the customer key. I'm using:

    var prox = new Script.Util.WSProxy();
var cols = ["Name","CustomerKey","CategoryID","IsSendable"];
var filter = {
    LeftOperand: {
        Property: "CustomerKey",
        SimpleOperator: "equals",
        Value: copyname
    },
    LogicalOperator: "OR",
    RightOperand: {
        Property: "Name",
        SimpleOperator: "equals",
        Value: copyname
    }
};

var desc = prox.retrieve("DataExtension", cols, filter);

Followed by

var prox2 = new Script.Util.WSProxy();
var cols2 = ["Client.ID","CustomerKey","DefaultValue","FieldType","IsPrimaryKey","IsRequired","MaxLength","ModifiedDate","Name","ObjectID","Ordinal","Scale"];
var filter2 = {
    Property: "DataExtension.CustomerKey",
    SimpleOperator: "equals",
    Value: copyname
};

var fields = prox2.retrieve("DataExtensionField", cols2, filter2); /* WSProxy Retrieve */

So it's taking the variable from some previous ampscript using GetValue and using that in the WSProxy retrieve as the customer key. However, I want it to look for the name, not the customer key, or at least use the @copyName to find the customer key of that DE, to use in the following code. I've tried the following without success:

  • Property: "DataExtension.Name"
  • Property: "DataExtensionName"
  • Property: "Name"
  • Property: "DataExtension.Name"

And I can't get the name from the first retrieve using desc.Results.Name either - it returns null. Can someone help me get this? Alternatively, a block of ampscript to run before the SSJS to get the CustomerKey from the Name would be even easier.

  • where did you get Dataextesnsion Name in Email template? – pkharries Oct 4 '18 at 10:05
  • @pkharries I'm not sure I understand - this isn't about an email template – TCassa Oct 4 '18 at 10:15
  • you need to get DataExtension name using DE customerkey? – pkharries Oct 4 '18 at 12:03
  • @pkharries - the other way round. People will type in the name of the DE into a form input and I need to be able to get the customer key for that. – TCassa Oct 4 '18 at 12:13
2

Using the following I was able to assign the DE CustomerKey to a SSJS variable via a filter on Name:

/* Grabs DE Object Info */
var prox1 = new Script.Util.WSProxy();
var cols1 = ["Name","CustomerKey","CategoryID","IsSendable"];
var filter1 = {
    Property: "Name",
    SimpleOperator: "equals",
    Value: yourName
};
var desc = prox1.retrieve("DataExtension", cols1, filter1);

var CustKeyStr = Platform.Function.Stringify(desc.Results[0].CustomerKey);

Please note that for some reason it would not allow me to pull the var without assigning an object number [0] to the path. Not sure why it would require this, but it works, so I am not questioning it. :)

| improve this answer | |
  • 2
    Thank you again for your help Gortonington. I don't know what I'd do without StackExchange!! – TCassa Oct 5 '18 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.