0

I am looking for a way to retrieve numeric values from sales cloud object fields to perform math calculations in Marketing Cloud.

My code will first get the values for Audience__c and RSVP__c from campaign object in sales cloud (which is working) and then using these 2 values to perform any simple math calculations.

Extra note: @key I used in RetrieveSalesforceObjects is obtained from my landing page url. (E.g My landing page URL is https://xxx?key=CampaignID)

%%[
var @totalaudiencecount, @rsvpcount, @key
SET @key = QueryParameter("key")
SET @totalaudiencecount= RetrieveSalesforceObjects('Campaign', 'Audience__c', 'Id', '=', @key)
SET @rsvpcount= RetrieveSalesforceObjects('Campaign', 'RSVP__c', 'Id', '=', @key)
]%%

The above portion is retrieval of sales cloud object field records based on a campaignID, do let me know if my usage of @key is correct. Besides that, I am facing issues to perform calculations from the above numeric fields. Assuming I want to add both values together, how should I proceed from here? I am suspecting the error is due to both values being retrieved as string values. Is there a way to retrieve both values (Audience__c and RSVP__c) in numeric type instead of string?

0

You can retrieve both the fields in a single call;

var @totalaudiencecount, @rsvpcount, @rs, @row

Set @rs= RetrieveSalesforceObjects('Campaign', 'Audience__c, RSVP__c', 'Id', '=', ID)
// Null check
IF NOT Empty(@rs) THEN 
    Set @row = ROW(@rs,1)
    Set @totalaudiencecount = FIELD(@row,"Audience__c")
    Set @rsvpcount = FIELD(@row,"RSVP__c")
ENDIF

VAR @sum
SET @sum = Add(@totalaudiencecount, @rsvpcount)

See if this works.

| improve this answer | |
  • RetrieveSalesforceObjects returns a rowset/array and you would have to retrieve a row from it before fetching variables. – Rajdeep Singh Oct 13 '17 at 18:23
  • Hi Rajdeep, thanks! Appreciate your help :) . However I am getting this error after I run the script in a landing page. Error Message: "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." – Valarie Simmons Oct 14 '17 at 6:33
  • I have also edited the post above to provide more info about how I am using retrievesalesforceobject function. Can you read the post again and let me know if my line of code is correct? Thanks again. – Valarie Simmons Oct 14 '17 at 6:56
0

Using Ranjdeep's solution as a reference, a sample of the actual solution is just this simple:

%%[ 
var @scintfields, @maxcount  

set @scintfields= RetrieveSalesforceObjects('Campaign', 'max_count__c', 'Id', '=', @campaignid)

Set @maxcount = FormatNumber(FIELD(ROW(@scintfields,1), 'max_count__c'),"F0")

]%%
| improve this answer | |

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.