Skip to content

Instantly share code, notes, and snippets.

@angrycider
Last active March 23, 2021 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angrycider/02e858fd013144e1bab3b422f7dad72e to your computer and use it in GitHub Desktop.
Save angrycider/02e858fd013144e1bab3b422f7dad72e to your computer and use it in GitHub Desktop.
5. Upsert row to a Data Extension
//UPSERT DE
var co = {
"CustomerKey": "7254CCBC-E5F8-49B6-991E-855825DAEADD",
"Keys":[
{"Key":{"Name":"subscriberkey","Value":"test@fakeemail.com"}}],
"Properties":[
{"Property":{"Name":"color","Value":"purple"}}
]
};
var uo = {
SaveOptions: [{"SaveOption":{PropertyName:"DataExtensionObject",SaveAction:"UpdateAdd"}}]
};
SoapClient.update('DataExtensionObject',co,uo, function(err, response){
if(err){
console.log(err);
}
else{
console.log(response.body.Results);
}
});
@mwj8410
Copy link

mwj8410 commented Jun 8, 2017

This appears to be an incorrectly formatted object for constructing the desired XML when updating more than one property.

As expressed here, the Properties object, when updating two or more property values would intuitively be

"Properties": [
  { "Property":{ "Name":"name1", "Value": "value1" }},
  { "Property":{ "Name":"name2", "Value":"value2" }}
]

... which gets parsed into XML as ...

<Properties>
  <Property>
    <Name>name1</Name>
    <Value>value1</Value>
  </Property>
</Properties>
<Properties>
  <Property>
    <Name>name2</Name>
    <Value>value2</Value>
  </Property>
</Properties>

Notice that each property gets expressed in a sibling Properties node. When this is interpreted by the remote system, only the last value is processed. To have the intended multi-value update, you have to change the Object nesting pattern slightly so that the constructed XML places the sibling node relationship at the Property level.

Properties: {
  Property: [
    {
      Name: 'name1',
      Value: 'value1'
    },
    {
      Name: 'name2',
      Value: 'value2'
    }
  ]
}

@jragsdaleSFDC
Copy link

I have tried both the original syntax as well as the updated version provided here and neither seem to work. Can you please provide an update on how to updateadd mutiple rows?

@syuraj
Copy link

syuraj commented Jul 19, 2019

Here is what worked for me.
@jragsdaleSFDC

const updateValues = {
	'Name': 'table_name',
	'Keys': [
		{ "Key": { 'Name': 'Key', 'Value': 'key_value' } }],
	"Properties": {
		"Property": [
			{ 'Name': 'Key', 'Value': 'key_value' },
			{ "Name": "ClientId", "Value": this.thCreds.ClientId },
			{ "Name": "ClientSecret", "Value": this.thCreds.ClientSecret },
			{ "Name": "WorkSpaceId", "Value": this.thCreds.WorkSpaceId },
			{ "Name": "SiteKey", "Value": this.thCreds.SiteKey },
			{ "Name": "BaseUrl", "Value": this.thCreds.BaseUrl }
		]
	}
};

const updateOptions = {
	SaveOptions: [{ "SaveOption": { PropertyName: "DataExtensionObject", SaveAction: "UpdateAdd" } }]
};


this.SoapClient.update(
	'DataExtensionObject',
	updateValues,
	updateOptions
	this.soapRetrieveCallback.bind(this)
);

@SunMartekVentures
Copy link

SunMartekVentures commented Mar 23, 2021

How can we upsert rows without primary key-value data extension?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment