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!
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
@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
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.
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")
Supriya, you mixed functions.
Here we should not use TextToDate, but FormatDateTime.
Hi, thank you for helping me but it its giving me this output.
Luana Silva
see my reply below
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.
Thank you all for helping me with this project. I couldn't have done this step without you.