0

I have created a simple email with 3 buttons (a href). The intended functionality is to select multiple values from the email. select A, B, C (buttons) and update multi-picklist values on salesforce ('CZV_Buying_Behaviour_FR__c') with the values chosen/clicked. But what it actually does its overwriting the first selection with the second.

Email code:

SET @url1 = CONCAT(CloudPagesUrl(1771),'&button=ORGUEIL')
SET @url2 = CONCAT(CloudPagesUrl(1771),'&button=ARGENT')
]%%
<table width="100%" border="0" cellspacing="0" cellpadding="0">

   <tr style="height:35px">
    <td>
     <a href="%%=RedirectTo(@url1)=%%" style="font: bold 11px Arial;text-decoration: none;background-color: #EEEEEE;color: #333333;padding: 2px 6px 2px 6px;border-top: 1px solid #CCCCCC;border-right: 1px solid #333333;border-bottom: 1px solid #333333;border-left: 1px solid #CCCCCC;">Landscape</a>
    </td>
<tr style="height:35px">
    <td>
     <a href="%%=RedirectTo(@url2)=%%" style="font: bold 11px Arial;text-decoration: none;background-color: #EEEEEE;color: #333333;padding: 2px 6px 2px 6px;border-top: 1px solid #CCCCCC;border-right: 1px solid #333333;border-bottom: 1px solid #333333;border-left: 1px solid #CCCCCC;">Nature and Wildlife</a>
    </td>
</tr>
</table>

CloudPage Code:

%%[
/*Data extensions used in AMPscript */
SET @SFDC_Contact_DE = 'SFDC_Contact_DE'


SET @CZV_Buying_Behaviour_FR__c = QUERYPARAMETER('button')

SET @Id = Id



SET @rs = RetrieveSalesforceObjects('Contact', 'Id, CZV_Buying_Behaviour_FR__c', 'Id', '=', @Id)
SET @result = UpdateSingleSalesforceObject('Contact',@Id,'CZV_Buying_Behaviour_FR__c',@CZV_Buying_Behaviour_FR__c)


]%%
<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>
 <meta name="description" content="">
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
  <p>%%=v(@CZV_Buying_Behaviour_FR__c)=%%</p>
  <p>%%=v(@Id)=%%</p>
</body>
</html>

Thanks

  • Can you tell me what %%=Field(Row(@rs,1),"CZV_Buying_Behaviour_FR__c")=%% looks like, please? Your update will replace whatever was there, so you'll need to read first and then update based on what was there before - adding or removing values from the array-type thing that CRM's stored in the field. – Macca May 18 '17 at 13:15
  • %%=Field(Row(@rs,1),"CZV_Buying_Behaviour_FR__c")=%% shows me the previous value I think. – hamza May 18 '17 at 14:24
  • Yes. If I understand your problem correctly, you need to parse what's in the previous value before you overwrite it completely with AMPScript. I'm assuming your multi pick list has [1,2] in it before they click on the button "3". You want the value of the field to now be [1,2,3], but what you end up with is [3]. If that's the scenario, you'd need to read what was there before into a variable, add/concatenate and then write back the new value. Maybe I'm misunderstanding the behaviour you're looking for. I'm not big on CRM, so my question was how does SFMC see the previous value. – Macca May 18 '17 at 14:39
  • Yes, exactly, the multi-picklist values look like 1;2;3. Could you please tell me how can I read what was before into a variable and concatenate with ";" for example? I'm a beginner on Ampscript. Thanks a lot. – hamza May 18 '17 at 14:43
  • The previous value clicked. – hamza May 18 '17 at 14:49
0

Could you give the following a go, please?

<!--
%%[
    /*Data extensions used in AMPscript */
    SET @SFDC_Contact_DE = 'SFDC_Contact_DE'
    SET @toAdd  = QUERYPARAMETER('button')
    SET @Id     = Id

    SET @rs     = RetrieveSalesforceObjects('Contact', 'Id, CZV_Buying_Behaviour_FR__c', 'Id', '=', @Id)
    SET @old    = FIELD(ROW(@rs,1),"CZV_Buying_Behaviour_FR__c")

    /* Check to see if the value to add already exists in multi-checklist */
    SET @oldVals = BuildRowsetFromString(@old, ";")

    SET @existsInOld = FALSE
    FOR @i = 1 TO ROWCOUNT(@oldVals) DO
        IF @toAdd == FIELD(ROW(@oldVals,@i),1) THEN
            SET @existsInOld = TRUE
        ENDIF
    NEXT @i

    /* If the new value is not already the multi-checklist, add it by concatenation */
    IF @existsInOld == FALSE THEN
        /* Check if there are any selections in the multi-checklist */
        IF ROWCOUNT(@oldVals) > 0 THEN
            SET @new = CONCAT(@old,";",@toAdd)
        ELSE
            SET @new = @toAdd
        ENDIF

        /* Update CRM with the new values */
        SET @result = UpdateSingleSalesforceObject('Contact',@Id,'CZV_Buying_Behaviour_FR__c',@new)
    ELSE
        /* Do nothing, you're wasting an API call to CRM */
    ENDIF
]%%
-->
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <p>%%=v(@new)=%%</p>
        <p>%%=v(@Id)=%%</p>
    </body>
</html>
  • Could you spit out %%=v(@existsInOld)=%% in the page to debug it. It should be "TRUE" if the Contact already has the value present. – Macca May 19 '17 at 7:25
  • It's working well thank you very much for your help ! – hamza May 19 '17 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.