0

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"
 %%[endif]%%

Error:

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"

0

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]%%

  %%=Format(@EstimatedFreightAmount,"$#,#.00;-$#,#.00")=%%

%%[ else
    SET @EstimatedFreightAmount = "FREE"
]%%

  %%=v(@EstomatedFreightAmount)=%%

%%[endif]%%

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

1
  • 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
0

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" 
EndIf 

]%%

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.