0

We are sending emails to opportunity's primary contact using Journey Builder. So when a new opportunity is created and the stage is 'stg1', the primary contact is injected in the journey.

In reality, there could be multiple opportunities associated with a Contact, so I want to pick up the opportunity which was just created (which got injected in the journey).

How do I find that most recent opportunity using AMPScript? I am using RetrieveSalesforceObjects() on Opportunity and using other fields from the object also

1 Answer 1

0

If you're using Data Stream, you may be able to use LookupOrderedRows().

%%[
var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i

set @lookupValue = "whee"
set @numRowsToReturn = 0 /* 0 means all */
set @rows = LookupOrderedRows("DataExtensionName",@numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

 for @i = 1 to @rowCount do

  var @DEColumn1, @DEColumn2
  set @row = row(@rows,@i) /*get row based on loop counter */
  set @DEColumn1 = field(@row,"DEColumn1")
  set @DEColumn2 = field(@row,"DEColumn2")

]%%

Row %%=v(@i)=%%, DEColumn1 is %%=v(@DEColumn1)=%%, DEColumn2 is %%=v(@DEColumn2)=%%

%%[

 next @i ]%%

%%[ else ]%%

 No rows found

%%[ endif ]%%
4
  • Not using datastream
    – Maneesh
    Commented Jul 7, 2016 at 11:56
  • May be worth it to get it configured. Another option could be retrieve all of the rows for the Contact with AMPScript, build a JSON object string and then use SSJS to sort it. Commented Jul 7, 2016 at 12:05
  • Hi Adam, is there any AMPScript function to find the no. Of rows returned by RetrieveSalesforceObjects() ?
    – Maneesh
    Commented Jul 7, 2016 at 12:07
  • Yes. Rowcount() Commented Jul 7, 2016 at 12:09

You must log in to answer this question.

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