2

I'm building a function that will retrieve data by certain criteria. However, not a single retrieve function will work with a shared data extension. Lookup Rows works, but not retrieve. Data extensions that are not shared work, but as soon as I change my D/E to the shared, I get an empty JSON.

Here is my code:

    <script language="JavaScript" runat="Server" excutioncontexttype="get">

    Platform.Load("Core","1.1");

    //Define my Data Extension this is the external key
    var myDE = DataExtension.Init('ent.myDE');

    //Simple lookup. This should return a couple of rows
    var filter = {Property:'Activity_Id',SimpleOperator:'equals',Value:'SomeDudesId'};
    var data = myDE.Rows.Retrieve(filter);

    //At this point I want the data to return as a JSON obj. 
    function retrieveData(){var jsonData = Stringify(data); return jsonData}
    retrieveData();

    //Printing this on the page because the microsite is in JSON format
    Write(Stringify(data));
    </script>

I am getting empty array everytime with this code.

1
  • Have you tried replacing "ent." with "ENT."? I don't think this is your issue, but it may be worth a go.
    – Macca
    Commented May 31, 2017 at 2:31

3 Answers 3

4

You should have to pass the DataExtension (DE) ExternalKey not DE name while defining DE. Just pass your DE ExternalKey in below code and you will get the matching records without any issues.

<script language="JavaScript" runat="Server" excutioncontexttype="get">
Platform.Load("Core","1.1");

var myDE = DataExtension.Init('932D2617-58DA-4F1F-9090-F07AB5DC9095'); //Pass DE ExternalKey 

var filter = {Property:'Activity_Id',SimpleOperator:'equals',Value:'SomeDudesId'};

var data = myDE.Rows.Retrieve(filter);

Write(Stringify(data));

</script>

Output: [{"Activity_Id":"5555","Name":"Test"}]

1
  • My apologies it is not clear on my code, but I am using the External Key
    – s.Lawrenz
    Commented May 31, 2017 at 12:55
4

So after much frustration, I have discovered that Platform and Core functions do not support the use of enterprise-level data extensions.

Here at the bottom explains that. So for anyone else with this problem, I suggest trying a mix of AmpScript and SSJS.

3

A little bit late reply but hope it helps someone in the future.

You can also use this:

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

var dataRows = Platform.Function.LookupRows('ENT.SHARED_DE_NAME',['COL1','COL2'],['VAL1','VAL2']);
 if(dataRows && dataRows.length > 0) {
      for(var i=0; i<dataRows.length; i++) {
           Platform.Response.Write(Stringify(dataRows[i]));
      }
 }

Documentation Here:

http://help.marketingcloud.com/en/documentation/server_side_javascript/server_side_javascript_syntax_guide/platform_server_side_javascript_functions/interact_with_data_extensions_using_the_function_object/lookuprows/

Just to keep it clean by avoiding mixing AMPScript and SSJS (not that there's anything wrong with that.)

You must log in to answer this question.

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