0

I'm trying the following code:

Platform.Load("Core", "1");
    var prox = new Script.Util.WSProxy();

    function addDE(DEKey) {
        var updateObject = {
            CustomerKey: DEKey,
            Properties: [{
                Name: 'Field1'
                Value: 'Field1'
            }]
        }

        var options = {
            SaveOptions: [{
                'PropertyName': '*',
                SaveAction: 'AddOnly'
            }]
        };
        var res = prox.updateItem('DataExtensionObject', updateObject, options);
    }
    var result = addDE("Test DE")

But I'm receiving the following error:

{
  "Status": "Error",
  "RequestID": "9478ef48-2a6e-405f-a08e-102bb8d1a4f6",
  "Results": [
    {
      "ErrorMessage": "SaveAction: AddOnly violation",
      "KeyErrors": null,
      "ValueErrors": null,
      "Object": null,
      "UpdateResults": null,
      "ParentPropertyName": null,
      "StatusCode": "Error",
      "StatusMessage": "SaveAction: AddOnly violation",
      "OrdinalID": 0,
      "ErrorCode": 68000,
      "RequestID": null,
      "ConversationID": null,
      "OverallStatusCode": null,
      "RequestType": "Synchronous",
      "ResultType": null,
      "ResultDetailXML": null
    }
  ]
}

I can't find any practical examples online on "SaveAction:AddOnly". Does this work?

1 Answer 1

2

In order to add only record you would use a different method - createItem, so that your code will look something like that:

<script language="javascript" runat="server">
Platform.Load("Core", "1");
    var prox = new Script.Util.WSProxy();

    function addDE(DEKey) {
        var updateObject = {
            CustomerKey: DEKey,
            Properties: [{
                Name: 'Field1',
                Value: 'Field1'
            }]
        }

        var res = prox.createItem('DataExtensionObject', updateObject);
    }
    var result = addDE("Test DE")
</script>

One more thing, do not forget a comma after Name: 'Field1'.

As an ultimate guide for such things, you can use this article.

1

You must log in to answer this question.

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