0

I'm sending 2 very similar SMSs on a journey and one of them is not working properly. When I preview it, it gives me this error:

Invalid value specified for function parameter. Function Name: DateAdd Parameter Name: InputDate Parameter Ordinal: 1 Parameter Type: Date Submitted Value: ClientID: 110008019 JobID: 0 ListID: 0 BatchID: 0 SubcriberID: 0 Data Source Type: CustomObject Data Source ID: 07e90d92-24f9-eb11-a304-48df37342d01

Since they are so similar, I don't know what could be causing the issue. Here are the codes for them:

SMS #1 (working fine):

    %%[ 
    VAR @hoje, @datalimite 
    SET @hoje = Now() 
    SET @datalimite = DateAdd(@hoje, 12, "D")
    
    InsertData("DE_TESTE_2WAY_AUM_LIMITE",DIA_ENTRADA,@hoje)
    
    ]%%

    **Other displayed text** Condicoes validas ate %%=Format(@datalimite, "dd/MM")=%%.

SMS #2 (not working correctly):

    %%[ 
    VAR @dataentrada, @datalimite
    SET @dataentrada = Lookup("DE_TESTE_2WAY_AUM_LIMITE","DIA_ENTRADA","CELULAR",MOBILE_NUMBER)
    SET @datalimite = DateAdd(@dataentrada, 8, "D")
    
    ]%%

    **Other displayed text** Condicoes validas ate %%=Format(@datalimite, "dd/MM")=%%.

I tried removing the DateAdd function and it works. I also tried displaying the @dataentrada field and it also works.

0

AMpscript function DateAdd throws the error in the second SMS because it cannot work with an empty value coming from the @dataentrada variable. In other words, your Lookup function results in an empty value and that is the problem here.

That is why your first SMS is working as expected, since the @hoje variable cannot be empty, it is always is set to reflect the current timestamp.

To cover this scenario, it would be recommended to check if Lookup brings any value and then if not - set either static fallback value for @datalimite, another way how to set this variable or change the output text to show error -

%%[

VAR @dataentrada, @datalimite, @Output_Text
SET @dataentrada = Lookup("DE_TESTE_2WAY_AUM_LIMITE", "DIA_ENTRADA", "CELULAR", MOBILE_NUMBER)

IF NOT EMPTY(@dataentrada) THEN
    SET @datalimite = DateAdd(@dataentrada, 8, "D")
    SET @Output_Text = Concat("Condicoes validas ate ", Format(@datalimite, "dd/MM"), ".")
ELSE
    SET @Output_Text = "No valid date is found."
ENDIF

]%%

**Other displayed text**
%%=v(@Output_Text)=%%

It is also easier to troubleshoot AMpscript in emails since you can preview the email without even any content and see how AMPscript would be processed.

Hopefully, it helps.

10
  • Hey, Niko! Thanks for your reply! I tried to display the @datalimite value and it displayed correctly, the value that is written on the DE. The first thing on the journey is an "update contact" that fills this field "DIA_ENTRADA", so technically it shouldn't be empty ever. Anyway, I'll try this and get back here if it works or not. And thank you for the tip on doing it in emails :)
    – Drake
    Aug 10 at 12:06
  • Hello, can you attach an example of the value you are pulling by this Lookup function, please? Yeah, I understood the flow but something is still incorrect with @datalimite since that is what the error is telling us.
    – Niko
    Aug 10 at 12:09
  • Hey, Niko! I just tried what you suggested and it worked as "bypassing" the error, but the message displayed is as it's an empty value. The value that I'm pulling is a DATE field and it's value is: "8/9/2021 2:32:40 PM"
    – Drake
    Aug 10 at 12:32
  • Ok, I have tried to hardcode your value and the format is fine. Since it bypassed the error and went to the ELSE path, then it definitely means that your Lookup function results in an empty value for some reason. Just to confirm, have you tried outputting this - %%=v(@dataentrada)=%%, not @datalimite as you mentioned before?
    – Niko
    Aug 10 at 12:55
  • 1
    Hey, Niko! I had to put a 10 minute wait in order to guarantee that the field was populated and it worked! Thank you so much for your attention and dedication :)
    – Drake
    Aug 11 at 13:26

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.