PixelPaul
PixelPaul

Reputation: 2767

Ampscript BuildRowsetFromString() fails on single item

I've been tasked with an ExactTarget task, which uses Ampscript. Trying to learn on the go here. See code snippet below:

%%[
    Var @testString, @testOutput
    Set @testString = Qwerty
    Set @testOutput = BuildRowsetFromString(@testString,"~")
]%%

TestOutput:%%= v(@testOutput) =%%

The code works if the testString contains a ~, but when there is no ~ character in the string, the ouput is blank. Is this correct by design? Do I need to add a conditional to check for the presence of the ~ character?

Upvotes: 1

Views: 1585

Answers (1)

edu8rdo
edu8rdo

Reputation: 214

That's the expected behavior. The BuildRowsetFromString() function alone isn't going to return any value when displayed, you're going to need to use Row() and Field() in order to pull the value out.

Using your example:

%%[
    Var @testString, @testOutput

    Set @testString = "Qwerty"
    Set @testOutput = BuildRowsetFromString(@testString,"~")

]%%

RowCount: %%=RowCount(@testOutput)=%%
TestOutput: %%=v(@testOutput)=%%

The RowCount() function returns a value of 1, essentially saying it knows there's at least one 'row' in there. To display that one value, you'll need to wrap that value with Field() and Row():

TestOutput: %%=Field(Row(@testOutput,1),1)=%%

If you want to display other values in the string, say you were passing "Qwerty~Second~Third", you'll need to either change the number at the Row() function or perform a loop.

References

Using Loops

BuildRowsetFromString() Function

Upvotes: 2

Related Questions