Record transformation examples.
Table of Contents
Example 1. Assign a default User (e.g. OwnerId lookup) to target record. ⇧
The configurations below assign default user Id to OwnerId lookup if the given user does not exist in the target org.
Using the core:RecordsTransform module. ⇧
The first solution uses the core:RecordsTransform and the constant sourceField pattern.
It allows to assign user Id dynamically by the given user's name which is usually the same in the source and in the target orgs.
Let's say, the Name of the default owner user to assign is: "Test Target User".
{
"objects": [
{
"operation": "Upsert",
"externalId": "Name",
"query": "SELECT Id, Name, Phone, OwnerId from Account WHERE Name IN ('ACC_10000', 'ACC_10001')",
"beforeUpdateAddons" : [
{
"module" : "core:RecordsTransform",
"args": {
"fields": [
{
"alias": "ownerId",
"sourceObject": "Account",
"sourceField": "OwnerId"
},
{
"alias": "defaultOwnerId",
"sourceObject": "User",
"sourceField": "Id",
"isConstant": true,
"lookupSource": "target",
"lookupExpression": "target.Name == 'Test Target User'"
}
],
"transformations": [
{
"targetObject": "Account",
"targetField": "OwnerId",
"formula": "formula.ownerId || formula.defaultOwnerId"
}
]
}
}
]
}
],
"promptOnMissingParentObjects": false
}
Using the ValueMapping. ⇧
The second solution uses ValuesMapping feature (this approach would be preferred when you know the exact target Owner Id value):
export.json:
{
"objects": [
{
"operation": "Upsert",
"externalId": "Name",
"deleteOldData": true,
"query": "SELECT Id, Name, Phone, OwnerId from Account WHERE Name IN ('ACC_10000', 'ACC_10001')",
"useValuesMapping": true
}
],
"promptOnMissingParentObjects": false
}
ValueMapping.csv file:
ObjectName,FieldName,RawValue,Value
Account,OwnerId,/^$/,0058d0000054PvGAAU
References: