-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_private.js
48 lines (41 loc) · 1.18 KB
/
_private.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var API = new Script.Util.WSProxy()
var AUTH_BASE_SFDC = 'https://login.salesforce.com/services/oauth2/token'
var AUTH_BASE_SFMC = 'https://1234.auth.marketingcloudapis.com/v2/token'
var utilMID = ''
/**
* Private method.
* Insert/Upsert a value into an SFMC data extension
* @param {string} ext Data extensions external key
* @param {object} data An object containing the data to write into the table
* @param {boolean} upsert Switches between operating modes; `upsert` == `false` means insert
* @returns {boolean}
*/
function processDataExtRow(ext, data, upsert) {
if (!ext || !data) {
return false
}
var rowData = {
CustomerKey: ext,
Properties: []
}
for (var key in data) {
rowData.Properties.push({
Name: key,
Value: data[key]
})
}
var response = undefined
if (upsert) {
var options = {
SaveOptions: [{
PropertyName: '*',
SaveAction: 'UpdateAdd'
}]
}
response = API.updateItem('DataExtensionObject', rowData, options)
} else {
response = API.createItem('DataExtensionObject', rowData)
}
// { Status: String, RequestID: String, Results: Array }
return response && response['Status'] == 'OK'
}