I am attempting to embed this script inside email body but getting an error when looking for empty tax data. I am interested to populate the word "FREE" from @EstimatedFreightAmount if no data exists in the XML.

On top of email:

SET @EstimatedFreightAmount = Field(Row(BuildRowsetFromXml(@xmldata, "//Order", 1), 1), 'EstimatedFreightAmount_att')

inside email body:

%%=Format(Field(Row(BuildRowsetFromXml(@xmldata,"//Order", 1), 1),'EstimatedFreightAmount_att'),"$#,#.00;-$#,#.00")=%%

 %%[if @EstimatedFreightAmount == "" then]%%
   @EstimatedFreightAmount = "FREE"


There is an error in your email. Please contact your customer service representative. Error 1: Script IF Statement Invalid
The script condition contains an invalid comparison operator. Condition: @EstimatedFreightAmount =""
Invalid Content:
if @EstimatedFreightAmount ="" then]%%--> @EstimatedFreightAmount = "FREE"


First I would wrap your XML part inside of a indexof conditional to ensure that the appropriate node exists before running the BuildRowsetFromXML:

%%[ IF IndexOf(@xmldata,'<Order') > 0 AND Indexof(@xmldata,'</Order>') > 0 THEN
      SET @EstimatedFreightAmount = Field(Row(BuildRowsetFromXml(@xmldata, "//Order", 1), 1), 'EstimatedFreightAmount_att')

   ENDIF ]%%

This will help remove the possibility of that node not existing and causing errors in your code.

Inside the body, I would adjust your code to:

if NOT EMPTY(@EstimatedFreightAmount) AND @EstimatedFreightAmount != "FREE" then]%%


%%[ else
    SET @EstimatedFreightAmount = "FREE"



This will then output 'FREE' if empty or @EstimatedFreightAmount is already set to Free. And if not, then it will display the formatted amount.

  • Thanks Gortonington - I was able to inject your body code below and it pulled well. I had the indexof already inserted inside the products ordered. Much appreciated! – Nomader May 21 '20 at 21:06

Here's another working solution.


SET @EstimatedFreightAmount = Replace(Trim(Field(Row(BuildRowsetFromXml(@xmldata, "//Order", 1), 1), 'EstimatedFreightAmount_att')),"-","") 

If Empty(@EstimatedFreightAmount) Then 
  SET @EstimatedFreightAmount = "FREE" 


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.