EDIT
I added in some comments in the code to better explain what it is doing. Hopefully that will alleviate some of your confusion.
The easiest and most elegant way I can think of to do this is to fill in those vars via a for loop.
Inside this loop you would dynamically set your track_pram_X
via a Rowset built from a String you created. You would then push this into a finalStr
variable that would house the whole query string value.
This would let you only put comma separator in those with values - but it does create a leading comma. To remove this, you just need to add in a Substring against the final result outside of the loop. Then you can do your original concat with a very slight change to use @finalStr
instead of listing each param with a comma.
Something like:
%%[
set @numStr = "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen"
/* numStr is a list of the number of tracking parameters. e.g. tracking_pram_one would be 'one' and tracking_pram_two would be 'two' in the list. This is not a list of the values for the tracking_prams */
set @numRowSet = BuildRowsetFromString(@numStr,',')
set @finalStr = '';
FOR @i = 1 TO Rowcount(@numRowSet) DO
SET @row = Row(@numRowSet,@i)
SET @tempName = Field(@row,1,0)
SET @attrName = CONCAT('track_pram_',@tempName)
/* attrName is used to piece together the constant 'tracking_pram_' to the dynamic value pulled from numStr (e.g. 'one' or 'two' to create 'tracking_pram_one' as the output */
SET @FieldSet = TreatAsContent(CONCAT('%','%[SET ', CONCAT('@',@attrName), ' = ATTRIBUTEVALUE("',@attrName,'")]%', '%'))
/* FieldSet is used to dynamically create AMPscript to set a dynamically named variable to a dynamically named attribute. It takes the attrName and creates an AMPscript variable with that name (e.g. @tracking_pram_one) and then sets that to equal the AttributeValue of that (e.g. AttributeValue("tracking_pram_one")). This is then compiled and output by the 'TreatAsContent()' function. */
SET @tempValue = TreatAsContent(CONCAT('%','%=v(',CONCAT('@',@attrName),')=%','%'))
/* tempValue is then created to house the actual value of the above set dynamic variable. Essentially meaning if in the sendable data 'tracking_pram_one is equal to '12345667' then tempValue would equal '12345667' */
IF NOT EMPTY(@tempValue) THEN
/* If tempValue is not empty, then it gets added into the 'final string' listing all the parameters */
SET @finalStr = CONCAT(@finalStr,',',@tempValue))
ENDIF
NEXT @i
/* This will cut off the leading comma via a Substring */
SET @finalStr = SUBSTRING(@finalStr,2,LENGTH(@finalStr))
/* This concats in the finalStr into your URL */
Set @URL = CONCAT('https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=', @finalStr, '&cntry_code=us&locale=en_US')
]%%
EXAMPLE OUTPUT:
from DE: