1

I tried to get all rows from DE by DE name, I got an empty array.

For the test, I tried to add a new record to this DE before the read function.

Edit: This is a Shared Data Extension

My code:

<script runat="server">
    Platform.Load('core', '1');
    try {
        var de = DataExtension.Init("ENT.DE_NAME");
        var data = {
            status: "status",
            errorMsg: "errorMsg"
        }
        Write("add: " + de.Rows.Add(data));
        Write("<Br>");
        var rows = de.Rows.Retrieve();
        Write(Stringify(rows));
    }catch(error) {
        Write(Stringify(error));
    }
</script>

Output:

add: 1
[]
0

For Shared Data extension, Platform and Core functions do not support the use of enterprise-level data extensions. So, you have to use a combination of SSJS and ampscript if you need.

Add another column named 'include' in your shared DE and add a default value as '1'

And try with the below code:

You can use SSJS for adding records and ampscript to retrieve records. This code will work for more than 2000 records as well.

   <script runat="server">
    Platform.Load('core', '1');
    try {
        var de = DataExtension.Init("ENT.Shared DE Name");
        var data = {
            status: "status",
            errorMsg: "errorMsg"
        }
        Write("add: " + de.Rows.Add(data));
        Write("<Br>");

    }catch(error) {
        Write(Stringify(error));
    }
</script>
%%[
SET @DECount = DataExtensionRowCount('ENT.Shared DE Name')
SET @RECORDS = LookupOrderedRows("ENT.Shared DE Name", @DECount, "status asc","include","1")
set @rowCount = rowcount(@RECORDS)
for @i = 1 to @rowCount do
Set @row = Row(@RECORDS,@i)
Set @value = Field(@row,"status")
Set @value2 = Field(@row,"errorMsg")
]%%
%%=v(@value)=%% <br>
%%=v(@value2)=%%
%%[
next @i
]%%

Let me know if you have any issues.

4
  • When I try to use the External key I get the error: "There was an error Adding the row(s).". When I try to remove the Rows.add function I still get an empty array.... – DanielRomano Apr 22 '20 at 12:47
  • @DanielRomano I have added the above code in my instance and am getting values. 1. Please make sure in your data extension you are adding having a column named - 'status ahd errorMsg'. 2. Also there shouldn't be any primary key and all the fields just make it as null – Naveen VM Apr 22 '20 at 13:17
  • Thank you for your help @razor All fields are "Nullable"... Please note it is a child BU. – DanielRomano Apr 22 '20 at 13:30
  • @DanielRomano I have updated my answer. Please try with that one. It works in my instance. Let me know if you have any issues. – Naveen VM Apr 23 '20 at 6:31

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.