I have the following code to retrieve the series of a product that has been purchased. We are using a loop because a contact might purchase multiple products.
%%[IF NOT EMPTY(@PersonAccountId)
THEN set @MyWatchesTable = RetrieveSalesforceObjects("My_Watches__c","Product__c","Person_Account__c", "=", @PersonAccountId,"Status__c","=", "Owner")
SET @rowCount = RowCount(@MyWatchesTable)
IF @rowCount > 0 THEN
FOR @counter = 1 to @rowCount DO
SET @MyWatchesRow = Row(@MyWatchesTable, @counter)
SET @Product = Field(@MyWatchesRow,"Product__c")
SET @ProductTable = RetrieveSalesforceObjects("Product2","Series__c","Id", "=", @Product)
set @productCount = RowCount(@ProductTable)
set @ProductRow = Row(@ProductTable, @productCount)
set @Series = Field(@ProductRow, "Series__c")
]%%
-->
Product %%=v(@counter)=%% : %%=v(@Product)=%%<br>
Series %%=v(@productCount)=%% : %%=v(@Series)=%% <br>
%%[ next @counter ]%% %%[ else ]%% No records found %%[ endif ]%%
<!-- %%[ENDIF]%%-->
I need to use the results of the loop to select the corresponding product checkbox if they own the product.
I wanted to concatenate the loop results
set @OutPutSeries = Concat(@counter, " ", @Product, " ", @productCount, " ", @Series, " ", next @counter)
and then use the the IndexOf
to determine if the concatenated result contains one of the products
/* Does it match; ; if no match, output of IndexOf(1,2) will be "0" */
if IndexOf(@Series,'Connected') > 0 then
Set @OutputSoldConnected = "True"
else
Set @OutputSoldConnected = "False"
endif
Then use the True/False result to pre-populate the checkbox
I have tried to use the indexOf
on the @Series
variable but it only returns the last result, that is why I thought about concatenating them but it did not work.
As @Mark G I had to set the variable before the loop
@ProductSeriesOutput
and declare the variable in the concatenation. Then I used the IndexOf
function to check if the value I needed for the preference was available and selected the checkbox if matched.
%%[IF NOT EMPTY(@PersonAccountId)
THEN
set @ProductSeriesOutput = " "
set @MyWatchesTable = RetrieveSalesforceObjects("My_Watches__c","Product__c","Person_Account__c", "=", @PersonAccountId,"Status__c","=", "Owner")
SET @rowCount = RowCount(@MyWatchesTable)
IF @rowCount > 0 THEN
FOR @counter = 1 to @rowCount DO
SET @MyWatchesRow = Row(@MyWatchesTable, @counter)
SET @Product = Field(@MyWatchesRow,"Product__c")
SET @ProductTable = RetrieveSalesforceObjects("Product2","Series__c","Id", "=", @Product)
set @productCount = RowCount(@ProductTable)
set @ProductRow = Row(@ProductTable, @productCount)
set @Series = Field(@ProductRow, "Series__c")
set @ProductSeriesOutput = Concat(@ProductSeriesOutput, @counter, @Series," ")
next @counter
else
endif
IF NOT EMPTY(@Series)
THEN
SET @HasTagHeuer = "True"
Var @OutputSoldConnected
/* Does it match; ; if no match, output of IndexOf(1,2) will be "0" */
if IndexOf(@ProductSeriesOutput,'Connected') > 0 then
Set @OutputSoldConnected = "True"
else
Set @OutputSoldConnected = "False"
endif
ENDIF
]%%
-->
<!-- %%[ENDIF]%%-->