AMPscript Field (Next)
Read a column from a rowset row with AMPscript Field in Marketing Cloud Next. Syntax and the outputs a Marketing Cloud Next email actually rendered, including where they differ from Engagement.
Syntax
Field(row, fieldName[, exceptionIfNotFound]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
row |
row | Yes | A row returned by Row(rowset, index) |
fieldName |
string | Yes | Name of the column to read |
exceptionIfNotFound |
string | boolean | number | No | In Next this did not control aborting: on rowsets built from a string, Field rendered this flag (true for true, 1, "true"; false for the other tested spellings, "1" included) instead of the cell, for existing and missing columns alike. Next saves true, false, 1, 0, "true", "false", "1", "0" |
Example
%%[
SET @rows = RetrieveSalesforceObjects("Contact", "Id", "IsDeleted", "=", "false")
IF RowCount(@rows) > 0 THEN
SET @idLength = Length(Field(Row(@rows, 1), "Id"))
ENDIF
]%%
%%=v(@idLength)=%%
Renders 18: the first Contact’s Id column was read as an 18-character record ID.
Return value
string — on a rowset from RetrieveSalesforceObjects, the value of the named column. On rowsets built from a string or from XML, Next returned the flag (third argument, true when omitted) instead of the cell; on a BuildRowsetFromJSON row it returned an empty string (see Behaviour).
Behaviour
Reads a column of a RetrieveSalesforceObjects row. Field(Row(@rows, 1), "Id") on a live Contact query returned an 18-character ID.
On a BuildRowSetFromString row it returns the flag, not the cell. With the row from BuildRowSetFromString("a,b,c", ",") stored in a variable, Field(@row, "Value") rendered true: the flag (third argument, true when omitted), not a. The nested inline form Field(Row(BuildRowSetFromString(...), 1), "Value") rendered true as well.
Field(row, 0) gave different results depending on how it was written. Written as SET @rows = BuildRowSetFromString("a,b,c", ","), SET @row = Row(@rows, 1), SET @v = Field(@row, 0), then %%=v(@v)=%%, it rendered true. The nested form %%=Field(Row(BuildRowSetFromString("a,b,c", ","), 1), 0)=%% broke the render (HTTP 500), as it aborts in Engagement (see BuildRowSetFromString).
The third argument shows up in the output. Next returns the flag, not the cell. On that same row, Field(@row, "Value", flag) rendered true for true, 1 and "true", and false for false, 0, "false", "0" and also "1". A missing column behaves the same way: Field(@row, "NoSuchColumn", flag) rendered true for true, 1 and "true", and false for 0, false, "0", "false", "1" and "notabool". None of these aborted.
A missing column without the third argument fails. An email with Field(@row, "NoSuchColumn") saved and published, but rendering it failed with HTTP 500.
An empty cell stays empty. On the empty third row of BuildRowSetFromString("a,b,", ","), Field(@row, "Value", "DEF") rendered an empty string; the third argument is not used as a default.
On BuildRowSetFromXML rows it returns the flag too. With XML built from Char() (so the email save does not strip the tags), the row count is right, but Field(Row(@rows, 2), "Value", 0) gives false instead of 200.00, and so do the Xml column and the origin_att and carrier_att columns read with 0. Reading by position (Field(row, 1) to Field(row, 5)) gives true. See BuildRowSetFromXML.
BuildRowsetFromJSON columns came back empty. On a row from BuildRowsetFromJSON whose Dest column holds NYC, both Field(@row, "dest") and Field(@row, 2) rendered an empty string.
Show Next test script
<!-- Marketing Cloud Next test script for Field. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[true] got=[%%=Field(Row(BuildRowSetFromString("a,b,c",","),1),"Value")=%%]</p>
<p>c2 expect=[false] got=[%%=Field(Row(BuildRowSetFromString("a,b,c",","),1),"NoSuchColumn",0)=%%]</p>
<p>c3 expect=[true] got=[%%[ SET @f1rs = BuildRowSetFromString("a,b,c",",") SET @f1r = Row(@f1rs,1) SET @f1v = Field(@f1r,"Value") ]%%%%=v(@f1v)=%%]</p>
<p>c4 expect=[] got=[%%[ SET @f2rs = BuildRowsetFromJSON('{"Flights":[{"Origin":"IND","Dest":"NYC","Price":100.0}]}', "$.Flights[*]", 1) SET @f2r = Row(@f2rs,1) SET @f2v = Field(@f2r,"dest") ]%%%%=v(@f2v)=%%]</p>
<p>c5 expect=[] got=[%%[ SET @f3rs = BuildRowsetFromJSON('{"Flights":[{"Origin":"IND","Dest":"NYC","Price":100.0}]}', "$.Flights[*]", 1) SET @f3r = Row(@f3rs,1) SET @f3v = Field(@f3r,2) ]%%%%=v(@f3v)=%%]</p>
<p>c6 expect=[false] got=[%%[ SET @f4rs = BuildRowSetFromString("a,b,c",",") SET @f4r = Row(@f4rs,1) SET @f4v = Field(@f4r,"NoSuchColumn",0) ]%%%%=v(@f4v)=%%]</p>
<p>c7 expect=[] got=[%%[ SET @f5rs = BuildRowSetFromString("a,b,",",") SET @f5r = Row(@f5rs,3) SET @f5v = Field(@f5r,"Value","DEF") ]%%%%=v(@f5v)=%%]</p>
<p>c8 expect=[truefalsetruefalsetruefalsefalsefalse] got=[%%[ SET @f6rs = BuildRowSetFromString("a,b,c",",") SET @f6r = Row(@f6rs,1) SET @f6v = Concat(Field(@f6r,"Value",true),Field(@f6r,"Value",false),Field(@f6r,"Value",1),Field(@f6r,"Value",0),Field(@f6r,"Value","true"),Field(@f6r,"Value","false"),Field(@f6r,"Value","1"),Field(@f6r,"Value","0")) ]%%%%=v(@f6v)=%%]</p>
<p>c9 expect=[false] got=[%%[ SET @f7rs = BuildRowSetFromString("a,b,c",",") SET @f7r = Row(@f7rs,1) SET @f7v = Field(@f7r,"NoSuchColumn",false) ]%%%%=v(@f7v)=%%]</p>
<p>c10 expect=[false] got=[%%[ SET @f8rs = BuildRowSetFromString("a,b,c",",") SET @f8r = Row(@f8rs,1) SET @f8v = Field(@f8r,"NoSuchColumn","false") ]%%%%=v(@f8v)=%%]</p>
<p>c11 expect=[false] got=[%%[ SET @f9rs = BuildRowSetFromString("a,b,c",",") SET @f9r = Row(@f9rs,1) SET @f9v = Field(@f9r,"NoSuchColumn","0") ]%%%%=v(@f9v)=%%]</p>
<p>c12 expect=[false] got=[%%[ SET @f10rs = BuildRowSetFromString("a,b,c",",") SET @f10r = Row(@f10rs,1) SET @f10v = Field(@f10r,"NoSuchColumn","notabool") ]%%%%=v(@f10v)=%%]</p>
<p>c13 expect=[true] got=[%%[ SET @fe2rs = BuildRowSetFromString("a,b,c",",") SET @fe2r = Row(@fe2rs,1) SET @fe2v = Field(@fe2r,"NoSuchColumn",true) ]%%%%=v(@fe2v)=%%]</p>
<p>c14 expect=[true] got=[%%[ SET @fe3rs = BuildRowSetFromString("a,b,c",",") SET @fe3r = Row(@fe3rs,1) SET @fe3v = Field(@fe3r,"NoSuchColumn",1) ]%%%%=v(@fe3v)=%%]</p>
<p>c15 expect=[true] got=[%%[ SET @fe4rs = BuildRowSetFromString("a,b,c",",") SET @fe4r = Row(@fe4rs,1) SET @fe4v = Field(@fe4r,"NoSuchColumn","true") ]%%%%=v(@fe4v)=%%]</p>
<p>c16 expect=[false] got=[%%[ SET @fe5rs = BuildRowSetFromString("a,b,c",",") SET @fe5r = Row(@fe5rs,1) SET @fe5v = Field(@fe5r,"NoSuchColumn","1") ]%%%%=v(@fe5v)=%%]</p>
<p>c17 expect=[true] got=[%%[ SET @fe6rs = BuildRowSetFromString("a,b,c",",") SET @fe6r = Row(@fe6rs,1) SET @fe6v = Field(@fe6r,0) ]%%%%=v(@fe6v)=%%]</p>
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @fe1rs = BuildRowSetFromString("a,b,c",",") SET @fe1r = Row(@fe1rs,1) SET @fe1v = Field(@fe1r,"NoSuchColumn") ]%%%%=v(@fe1v)=%%
Differs from official docs
- The cell value is not returned on
BuildRowSetFromStringandBuildRowSetFromXMLrows. The reference describesFieldas handing back the content of the named column. On the first row ofBuildRowSetFromString("a,b,c", ","), Next renderedtrueforField(@row, "Value")instead ofa, and with an explicit third argument it rendered that flag astrueorfalseinstead of the cell. The flag also comes back onBuildRowSetFromXMLrows (Value,Xmland attribute columns) and on theValuecolumn ofBuildRowsetFromJSONrows, while named object columns ofBuildRowsetFromJSONrows andRetrieveSalesforceObjectsrows return the value. Card - The third argument does not decide between empty string and error. The reference says a falsy flag gives an empty string for a missing column and a truthy (default) flag raises an error. In Next, a missing column on a
BuildRowSetFromStringrow renderedfalseforfalse,0,"false","0"and also"1", and renderedtruefortrue,1and"true", without any error. On aBuildRowsetFromJSONrow, the two-argument call on a column that is not there rendered an empty string instead of failing. Only the two-argument call on aBuildRowSetFromStringrow failed (HTTP 500). Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
On a row from BuildRowSetFromString("a,b,c",","), Engagement’s Field(row,"Value") returns a where Next returns the flag (third argument, true when omitted), not the cell. With a missing column, Engagement returns an empty string for a falsy third argument and aborts for a truthy one; Next renders the flag as true or false instead of either. Engagement reads a BuildRowsetFromJSON column by case-insensitive name or by ordinal (NYC); Next returned an empty string for both. On BuildRowSetFromXML rows Engagement returns the node content (200.00, IND); Next returns the flag (false for Value, Xml and attribute columns read with 0, true by position). Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
Row— returns the row this reads fromRowCount— guard before reading a rowRetrieveSalesforceObjects— the rowset source Field read correctly- Official reference