32
Views
9
Comments
Solved
If condition

Hi,

I'm having a little problem here. I want to create an if condition that checks the acquisition date and the number of warranty years for a computer. If the sum of these two values results in a date greater than or equal to the current date, it should display something like:

"Warranty until: [calculated date]"

Otherwise, if the calculated date is before the current date, it should display:

"Without warranty"

I'm trying to implement this, but I keep getting an error, as shown in the image.

The data types are as follows:

  • Date of purchase: GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao (Data type: Date)

  • Warranty (in years): GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia (Data type: Integer)

Thank you all in advance!

erro.PNG
UserImage.jpg
Supriya Malla
Solution

Hi @Nuno Reis,

Thanks for pointing that out! You're right, I should have used FormatDateTime instead of TextToDate:


If(AddYears (GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao ,GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia ) >= CurrDateTime(), "Warranty until: "+ FormatDateTime(AddYears(GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao ,GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia )

,"dd/MM/yyyy"),"Without warranty") 

Appreciate your help! 

Thanks,

Supriya

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

@Luana Silva ,

your whole expression results in a text string, but it looks like you are using that expression in the condition of an If node.  That doesn't match.

Dorine

UserImage.jpg
Supriya Malla
Solution


Hi @Luana Silva,

As Dorine pointed out, the expression you’re using outputs text. When used in an if condition, it will throw an error because if statements require a boolean (true/false) value.

If you want to assign the output of this expression to variable, you can do that within an Assign action, or if you just need to display the result, you can use it in an Expression or in a Message.

UserImage.jpg
Supriya Malla

Hi @Luana Silva,

Try the following – it will work in an Expression or Message: 

If(AddYears (GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao ,GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia ) >= CurrDateTime(),"Warranty until: "+TextToDate(AddYears(GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao ,GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia )),"Without warranty")

Thanks,

Supriya


2016-04-22 00-29-45
Nuno Reis
 
MVP

Supriya, you mixed functions.

Here we should not use TextToDate, but FormatDateTime.

UserImage.jpg
Supriya Malla
Solution

Hi @Nuno Reis,

Thanks for pointing that out! You're right, I should have used FormatDateTime instead of TextToDate:


If(AddYears (GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao ,GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia ) >= CurrDateTime(), "Warranty until: "+ FormatDateTime(AddYears(GetEquipamentoById.List.Current.InventarioEquipamentos.DataAquisicao ,GetEquipamentoById.List.Current.InventarioEquipamentos.AnosGarantia )

,"dd/MM/yyyy"),"Without warranty") 

Appreciate your help! 

Thanks,

Supriya

2023-05-15 15-43-24
Luana Silva

Hi, thank you for helping me but it its giving me this output.


Luana Silva

Capturar.PNG
2021-09-06 15-09-53
Dorine Boudry
 
MVP
UserImage.jpg
Supriya Malla
Solution


Hi @Luana Silva,

As Dorine pointed out, the expression you’re using outputs text. When used in an if condition, it will throw an error because if statements require a boolean (true/false) value.

If you want to assign the output of this expression to variable, you can do that within an Assign action, or if you just need to display the result, you can use it in an Expression or in a Message.

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

@Luana Silva ,

your whole expression results in a text string, but it looks like you are using that expression in the condition of an If node.  That doesn't match.

Dorine

2024-01-04 09-21-21
Venkatesaiya

Hi @Luana Silva ,

   I think you are storing a value from an expression in a variable with Boolean data type. Please change the variable to Text data type because the expression returns a text value. 

2023-05-15 15-43-24
Luana Silva

Thank you all for helping me with this project. I couldn't have done this step without you. 


Luana Silva

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.