- Generate guid id
- Enable foreach parallelism
- ADO pagination
- Spaces in ADO names
- Alternative queries
Here are several tips and advices for using the Azure Logic App. Some workflows are not obvious. Hope it will help you save your time.
Generate guid id
To insert a new document in a cosmos collection you have to use an id. However, if you use guid() function inside the document template it will work only in case of non-id PK (partition key). But for most cases, PK should be an id. Hence you should use the same guid in both the document and partition key, it is obvious. If call guid() twice, two different guids will be returned.
To solve this problem, we have to generate a guid before the insertion. To do it, use Compose logic block.
After that, we can use pre defined value inside the insertion block.
P.S. do not forget to set quotes around partition key value, or you will face with a weird error 🙂
Enable foreach parallelism
If you work with a set of documents you usually use Foreach block. Assume a case you need to make a query inside the loop.
In case of many ADO items Foreach block will literally DDOS ADO server. It will cause error 429 (too many requests). To reduce amount of requests we can adjust the level of the parallelism for a loop.
This setup works much longer, of course but ADO server will swallow all of them.
In addition, if you ADO server has an aggressive firewall setup you can add a delay block inside a loop to reduce a frequency of sending requests.
In case of your ADO query returns more than 1k items you have to configure ADO query block to handle this situation. To do it open settings and set page size.
A problem here can be there if you set maximum threshold (1k). In this case block returns an error. So use small page size like here: 100.
Spaces in ADO names
If you ADO organisation or project has spaces in name then you have to escape spaces with %20. Just like that:
Escape is good but it could be a nightmare when you handle big query (SQL or Kusto). In this case I recommend to use a conditional block and not try to escape all the lines of a query and inline it.
Azure logic apps platform might be useful if you need fast development or you ask one junior do to stuff. Of course it has some not obvious things and even pitfalls. Some of them I’d faced with I presented here. If I find new I also write it down and post in my twitter (you can follow one:).
Read other Azure related articles by tag Azure