WSProxy Data Extension AddOnly bug

cloudpagemarketing-cloudssjswsproxy

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?

Best Answer

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.

Related Topic