0

I have a requirement to cancel a send if certain conditions are not met. My current code cancels the send, but does not log the conditions. According to the RaiseError Documentation, the last term (boolean)

Indicates whether the function records information to data extensions before error occurs, even if the process skips the subscriber. A value of 1 retains information written to data extensions before the error occurs, even if the subscriber is skipped. A value of 0 does not retain information recorded before the error. This parameter refers to inserted, updated, upserted, or deleted information via AMPscript.

so if my understanding is right, putting a value of 1 here so log the error.

Here is a copy of my code:

SET @rows2 = LookUpOrderedRows('ENT.Presend Agreement Log',1,'DateAdded Desc','email_name',emailname_) 
IF RowCount(@rows2) == 0 
    THEN 
        SET @Message ="Loren Ipsum"

/*Should this be an upsert??*/

UpsertDE('ENT.Presend Agreement Error Log',1,
           'email_name',emailname_,
           'error_message',@Message)
RaiseError(@Message, false,1)
ENDIF

Would appreciate any pointers here

3
  • 2
    Your RaiseError() function is only using 3 parameters. The documentation says to set the 5th parameter in order to retain the information recorded? Looks like you are just setting the API Error Code to be 1? Commented Jun 4, 2018 at 1:46
  • @TravisNaughton you could be right..but 3 and 4 are strings...if thought putting 1 as a boolean would bypass them since they are optional
    – 0xsegfault
    Commented Jun 4, 2018 at 1:53
  • The documentation is a bit all over the place. It says that it should be boolean but the example says to use an integer as a boolean. I wouldn't have thought it would handle bypassing variables, but will be interested to see if you can. Commented Jun 4, 2018 at 3:36

2 Answers 2

6

AMPScript does not have any named parameters, so all parameters must be passed by position. In this case, the RaiseError function has 5 parameters and you are trying to specify the 5th without specifying the 3rd or 4th. This means that your code is raising API error code 1 and then ignoring the next two optional parameters.

I believe the convention to ignore optional positional parameters in AMPScript is to use an empty variable, typically @null. This means your code to raise the error should be:

RaiseError(@Message, false, @null, @null, 1)

EDIT 2020-11-24: Adding in caveats from the comments for better visibility as it affects the answer.

It seems as though the function does not allow for null values, so you should instead find an API error code and API error number that makes sense for your example.

For example: error 7000, Email failed validation: [validation error].

You can find a list of API errors here

Sample of final RaiseError call:

RaiseError(@Message, false, "Email Failed Validation", 7000, 1)
4
  • using the the line of code you provided but getting this :
    – 0xsegfault
    Commented Jun 5, 2018 at 11:45
  • The function expression is invalid. See inner exception for detail. Script: RaiseError(@ Message, false, @ null, @ null, 1) Index: 22 ListID: 0 An error occurred when attempting to evaluate a RaiseError function call. See inner exception for details. Invalid value specified for function parameter. Function Name: RaiseError Parameter Name: ErrorCode Parameter Ordinal: 3 Parameter Type: Numeric Submitted Value: ClientID: 7297215 JobID: 0 ListID: 0 BatchID: 0 SubcriberID: 262692048 Data Source Type: CustomObject Data Source ID: b5671a1f-ff8d-e711-b071-38eaa71585b9
    – 0xsegfault
    Commented Jun 5, 2018 at 11:45
  • Do I need to initital the @ null variables to 0 or Null first?
    – 0xsegfault
    Commented Jun 5, 2018 at 11:46
  • 1
    No AMPscript variables that have not been initialized should default to a null value. It seems as though the function does not allow for null values, so you should instead find an API error code and API error number that makes sense for your example. For example, error 7000, Email failed validation: [validation error]. You can find a list of API errors here.
    – ncv
    Commented Jun 15, 2018 at 16:15
1

I was having this same issue and in classic Marketing Cloud fashion, the solution seems to be something that makes no sense. You have to SET whatever Data Extension function you want to persist even if the RaiseError is triggered.

So, instead of...

UpsertDE('ENT.Presend Agreement Error Log',1,
           'email_name',emailname_,
           'error_message',@Message)

Use...

SET @UpsertSomething = UpsertDE('ENT.Presend Agreement Error Log',1,
           'email_name',emailname_,
           'error_message',@Message)

...and the data will be retained, even when the RaiseError cancels the send.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .