Template Expression

behavior
(Vlad Roman) #1

Hi,

I know it’s a long shot but maybe it is possible.
Currently my app generates an email with a PDF attachment. This PDF is an order with order items and details which i’ll be sending to a factory to order those items/products. Some items are in stock in my warehouse. Is it possible when the PDF is generated to make an API call to my stock database and based on IF condition to exclude the items in my stock?
EX: <<Start: [ITEMS]>> <<If: [CONDITION BASED ON API CALL RESULT VALUE] >> <<[ITEM]>> <><>

Thank you!

(Philip Garrett) #2

We do not yet provide a way for you to make an HTTP Get call and return a result that you can use in your app. We do plan to add that capability before too much longer.

If the stock data was present in an AppSheet table, then you could use an <If:> expression to conditionally include or exclude individual items from the resulting PDF. See https://help.appsheet.com/behavior/workflow-sending-email/template-if-expressions

(Aleksi Alkio) #3

Though you could do that for example with scripting if your database has a Rest API.

(Philip Garrett) #4

Hi Aleksi,

I agree that it is possible to invoke a REST API from script.

If I understand his question correctly, he is asking if he can invoke a REST API from an <> expression in the template, and use the returned value to decide whether to list that item in the resulting email document.

If that is his question, I do not know how he can invoke a REST API from an <> expression.

We are planning to add the ability to perform an HTTP GET or POST and use the result returned by the GET or POST in an expression. If we had that capability now, I can see how he could use it to determine if the SQL database contained the item. In the absence of this feature, I am not sure how to do what he is asking.

I hope there is another way to accomplish what he is asking. I defer to you on that, because you have a lot more experience building apps than I do.

(Aleksi Alkio) #5

@Phil I was not thinking to invoke from an <> expression… I was thinking to trigger a webhook with the same kind of IF statement.

(Levent Kulacoglu) #6

@Phil
Provided you set an onChange() script with the Google Document, you can parse any text from the gDoc body text and if it includes a specific text, you can then invoke a REST API call and paste the its JSON response inside the body. However, with AppSheet I believe that is not possible because the workflow template will already be pushed to PDF parser before that API call returns its response.

However, concur with @Aleksi that it can be done calling a webhook.