-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ttntm/feature/cso
feature: createSalesforceObject()
- Loading branch information
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Create a record in an SF CRM object | ||
* @param {string} type SF CRM object API name, i.e. 'Contact', 'ema_CustomObject__c' | ||
* @param {object} props An object containing the new record's fields and values | ||
* @returns {object | undefined} | ||
*/ | ||
function createSalesforceObject(type, props) { | ||
if (!props || !type) { | ||
return undefined | ||
} | ||
|
||
var fieldsCount = 0 | ||
var recordData = [] | ||
|
||
for (var key in props) { | ||
fieldsCount++ | ||
recordData.push(key) | ||
recordData.push(props[key]) | ||
} | ||
|
||
var createSFObject = ""; | ||
createSFObject += "\%\%["; | ||
createSFObject += "set @SFCreate = CreateSalesforceObject('" + type + "',"; | ||
createSFObject += fieldsCount + ",'" + recordData.join("','") + "'"; | ||
createSFObject += ")"; | ||
createSFObject += "output(concat(@SFCreate))"; | ||
createSFObject += "]\%\%"; | ||
|
||
var execCreate = Platform.Function.TreatAsContent(createSFObject) | ||
|
||
return execCreate && typeof execCreate === 'string' && execCreate.length === 18 | ||
? { id: execCreate } | ||
: { error: 'Error creating SF record' } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters