1

This question is more from an understanding perspective. I am trying to implement omnichannel solutions for a client using Saleforce Data Cloud (SDC) as CDP and SFMC for deployment of messages.

The concern I am seeing with SDC is when it activates segments to SFMC all the related attributes (those are usually the field that will be used for personalization in messages) come in JSON format. This is challenging if I have to parse that JSON field in SFMC to read the data and then use it for any decision splits or personalizations?

I wanted to know how do other clients usually work with SDC and SFMC together?

1 Answer 1

1

I'm no SDC expert but I have the same problem with a client. Currently I've created a combination of ssjs and ampscript to parse the json string and loop through it to set the variables as ampscript variables within the email. This way each variable will be set with the same name as received by SDC

It can be inserted in the top of the email if needed. looks something like this:

    %%[ SET @json = AttributeValue('XXXX')
    IF not empty(@json) THEN
    SET @rows = BuildRowsetFromJson(@json, '$[*]', 1)

SET @rowcount = rowcount(@rows)
if @rowCount > 0 then

]%%

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

        var rawData = Variable.GetValue("@json");
        var jsonData;

        try {
          jsonData = eval('(' + rawData + ')');
        } catch (e) {
          Write("Error parsing JSON: " + e);
        }

        if (jsonData) {
          var keys = [];
          for (var key in jsonData[0]) {
            if (jsonData[0].hasOwnProperty(key)) {
              keys.push(key);
            }
          }
          Variable.SetValue("@AllKeys", keys.join(";"))
        }
</script>

%%[
  
SET @rowSet = BuildRowSetFromString(@json, ",")
SET @commaCount = RowCount(@rowSet)
SET @row = row(@rows,1)
SET @keyString = BuildRowSetFromString(@AllKeys, ";")
SET @keyCount = rowcount(@keyString)

IF @commaCount == @keyCount THEN SET @rowCount = @commaCount
ELSEIF @commaCount > @keyCount THEN SET @rowCount = @keyCount
ELSEIF @commaCount < @keyCount THEN SET @rowCount = @commaCount
ENDIF

for @counter = 1 to @rowCount do

SET @value = Field(@row, @counter)

SET @keyRow = row(@keyString, @counter)
SET @keyValue = Field(@keyRow, 1)

TreatAsContent( Concat( "%", "%[ SET @", @keyValue, " = ", @value, "]%", "%") )

 NEXT ELSE ENDIF ELSE ENDIF

]%%

You must log in to answer this question.

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