template If statement syntax wrong, unsure what to write and can't find in documentation

Hi,

If the change was an add, I want to write one string, if the change was an update I want to write another. Sounds simple but ive spent the last hour or more trying everything I can to try get it working and I can't work it out.

my code:
 -:-<<_UPDATEMODE>> -:- <<If: (_UPDATEMODE = “Update”)>>Note updated<<EndIf>> -:-

The Result:

-:-Update -:- -:-

As expected it writes "Update", but after that its blank. ive tried square brackets around updatemode, <<>> around updatemode, with and without quotes on Update, removing the round brackets, changing from = to <> does make the text show, so that does show that the if statement is working, if they arent equal ( <> ) then it does show the text, but they are never equal. Right before the if statement im writing out the value of update mode, which is seen as Update. So I guess my issue is the left side of the equals in the if statement isn't reading the update mode value properly, or more so im not putting it in correctly.

been trying everything I can think of with no success, im sure its something very simple so any help would be great thank you!

Solved Solved
0 11 436
1 ACCEPTED SOLUTION

I got it working! So as @Steve said, _UPDATEMODE is a template variable. Template variables are not available within expressions. I have then used [_THISROW_BEFORE] to check if it exists or not. If it is blank then its an added row, if it does exist then its an added row. Im not deleting records but I assume you could check if after doesn't exist and that would be a delete

Note <<If: (ISBLANK([_THISROW_BEFORE]))>>added<<EndIf>><<If: (ISNOTBLANK([_THISROW_BEFORE]))>>updated<<EndIf>> for <<[Ticket ID].[Story Type]>>: <<[Ticket ID].[Title]>>

Results in:

Note updated for Task:
Note added for Task:

 

View solution in original post

11 REPLIES 11

The most obvious answer is to use a bot.  Since you can choose the trigger for the bot to be either "Add only" or "updates only".  So you'd need two bots and presumably they call 2 seperate actions to write 2 seperate strings.

Simon@1minManager.com

It might be the most obvious answer, but it’s not the best solution. That doubles the amount of bots, tasks, and email templates.  If it was only 2 or 4 then that would be ok. But if I want to have 20 different email notifications setup, then that doubles it to 40. 

it means maintaining a heap more things, whereas a simple if statement can make it more reusable, one template file, task, and bot for handling add note, change note, assign new user to note. This would otherwise need 3 different ones. Then when I change a template I have to change it 3 times instead of one. 

Steve
Platinum 4
Platinum 4

_UPDATEMODE is a template variable. Template variables are not available within expressions.

Oh wow ok, that’s a shame. Thank you for that. Do you know if it’s mentioned anywhere in the documentation? I read all the related doc pages multiple times over last night trying to sort this out. 

I wonder why template variables can’t be used in expressions?

Oh just had an idea, I remember seeing in the documentation a reference in square brackets that was something like before update and after update and it had an example comparing the two in a template if statement. I guess using that I could check if the before save exists, if so that’s an update, if it doesn’t exist that an add. I’ll look into it and see how it goes  

I got it working! So as @Steve said, _UPDATEMODE is a template variable. Template variables are not available within expressions. I have then used [_THISROW_BEFORE] to check if it exists or not. If it is blank then its an added row, if it does exist then its an added row. Im not deleting records but I assume you could check if after doesn't exist and that would be a delete

Note <<If: (ISBLANK([_THISROW_BEFORE]))>>added<<EndIf>><<If: (ISNOTBLANK([_THISROW_BEFORE]))>>updated<<EndIf>> for <<[Ticket ID].[Story Type]>>: <<[Ticket ID].[Title]>>

Results in:

Note updated for Task:
Note added for Task:

 

That’s where I got it from yes, however it doesn’t say anywhere that the template variables can’t be used in expressions. 

 


@Steve wrote:

_UPDATEMODE is a template variable. Template variables are not available within expressions.


Hi @lizlynch ,

Request you to update the help documentation with @Steve 's guidance on built-in template variables in the article below.

Use variables in templates - AppSheet Help

 

Steve
Platinum 4
Platinum 4

@clintinthecode wrote:

That’s where I got it from yes, however it doesn’t say anywhere that the template variables can’t be used in expressions. 


Why would you think they could be?

I guess I just assumed it would work as both template variables and expressions go inside << >> 

The double brackets are used to invoke a template variable, and the same double brackets are used to invoke an expression, so it was logical to me that I could use both template variables and expressions within double brackets together. 

in my mind if they can’t be used together they should have a different method of using them, eg use << >> for template variables, and {{ }} for expressions. This way its completely obvious they cannot be used together

@clintinthecode @Suvrutt_Gurjar 
Thanks for raising this issue and for the suggestion to update the documentation. I've updated the topic to indicate that it can be used in templates and when configuring certain automation properties. Apologies for the confusion.

Liz

Top Labels in this Space