0

I want to perform data updates based on data that is in a DE, if the Contact_Id of the case is the same as what is in the DE then perform the modifications that are in the variables

but when I run the script there is no change to the case in Salesforce and it remains pending (and does not change to Completed Service and then closes the case) what am I doing wrong?

Platform.Load("Core", "1.1.1");
    try {
        var closeReason = "Aluno realizou o pagamento do feirão";
        var status = "Atendimento Concluído";
    
        var deCustomerRows = DataExtension.Retrieve("Base_pagamentos_feirão", ["Contact_Id"]);
    
        if (deCustomerRows && deCustomerRows.length > 0) {
            for (var i = 0; i < deCustomerRows.length; i++) {
                var contactId = deCustomerRows[i]["Contact_Id"];
    
                var updateResult = Platform.Function.UpdateSingleSalesforceObject(
                    "Case", contactId,
                    ["CloseReason__c", "Status", "IsClosed"],
                    [closeReason, status, "true"]
                );
            }
        }
    } catch (e) {
        // Lidar com erros, se necessário
    }
    

1 Answer 1

0

There is no such SSJS Platform function to update CRM objects. It only exists in AMPscript - UpdateSingleSalesforceObject.

However, you can still execute that AMPscript function in SSJS by correctly wrapping it -

<script runat = "server">
Platform.Load("Core", "1");

try {

var ObjectName = "Case";
var Id = contactId;
var Fields = ["CloseReason__c", closeReason, "Status", status, "IsClosed", "true"];

var updateSFObject = "";
    updateSFObject += "\%\%[ ";
    updateSFObject += "set @UpdateSingleSalesforceObject = UpdateSingleSalesforceObject('" + ObjectName + "',";
    updateSFObject += "'" + Id + "', '" +  Fields.join("', '") + "'";
    updateSFObject += ")";
    updateSFObject += "]\%\%";
Platform.Function.TreatAsContent(updateSFObject);

var results = Variable.GetValue("@UpdateSingleSalesforceObject")

} catch (e) {
    Write(Stringify(e));
}
</script>

More info here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .