In this post, I will show the problems I’ve encountered while creating an application based on WEBCON BPS. How I used the Python script in WEBCON BPS using a standard “Run a PowerShell script” action.
In the previous article, I wrote about how using WEBCON BPS I created an application to automatically generate a menu for a ketogenic diet for several days. In today’s article, I will focus on how I managed to do it without using the SDK action and how the “Run a PowerShell script” action saved my project.
Fail fast approach
Starting to create the application, I wasn’t sure if it would be possible to fully implement all planned functionalities using WEBCON. However, to be able to verify it in the first place, I prepared the skeleton of dictionary processes, I did not focus on how I will draw recipes. I assumed it would be easy – somehow. Just draw random recipes and it’s ready. As it turned out later, it is not easy at all (at least for me).
The first problem – how to get random subset from the set of recipes
The assumption that the draw would be easy to do was a big mistake. The first problem I got stuck on was creating an algorithm that will randomly draw a set of recipes with given parameters. As it turns out, this is not a trivial problem. For example – try to draw from the set of numbers [1, 2, 3, 3, 4, 5, 6] those that will give the sum 9. Did you succeed? As you can see, we have several possible subsets: [1, 2, 3, 3], [3, 6], [4,5], etc. Now, let’s add another condition: the number of numbers to draw. Additionally, you may find that the subset does not have exact values and you will need to approximate. I started looking for solutions on the Internet. The search led me to this page about the Perfect Sum Problem.
However, I still didn’t quite know how to put this knowledge into practice. Just because of the fact that our set, from which we draw, consists of complex objects that are not single numbers. Each recipe has ingredients such as carbohydrates, proteins, fats where each of them must be taken into account.
First Lifebuoy – a colleague programmer
Rescue from this oppression turned out to be a consultation with a programmer I know, who was able to help me. He suggested how to solve the problem of drawing recipes from the prepared set, along with many additional parameters (chapeau bas Marcel Zięba). He prepared and explained to me a Python script that used the PuLP library. This library is used to solve linear programs in Python. Thanks to this, and my SQL views (recipes and simulation orders) based on WEBCON BPS database, the program downloaded and randomized a set of recipes with specific parameters. Then saves back results in the prepared custom SQL table.
NOTE: The following screens show tables and views that are based on WEBCON BPS content database. This solution is not recommended by WEBCON – tables and views should be prepared in a separate database. Interference and execution of operations in the WEBCON BPS content database may result in irreversible changes and loss of WEBCON warranty!
The solution that causes another problem
The script written in python worked like a charm. Unfortunately, I had to execute it manually. I quickly concluded that using it this way is uncomfortable and really frustrating. Despite the fact that I have basic programming knowledge, I don’t know yet how to create SDK add-ons for WEBCON BPS. Of course, I hope that soon I will be able to make up for these shortcomings. Also, I am not sure if the express version license allows the use of the SDK. So in the first place, I was looking for other solutions that do not require SDK. I decided to try using PowerShell action.
The use of PowerShell actions enabled the script to be run from WEBCON BPS on a transition path. Of course, I am aware that this is not a perfect solution and it is a workaround. Action is not executed in the transaction and basically, it’s a bad practice. However, for my needs it is a sufficient solution – remember – done is better than perfect!
In this lengthy post, I wanted to show that skillful use of “Run a PowerShell script” action may be the last resort for projects that have no other options (e.g. no proper API, or no SDK). In my case, I am using *.py file, but you should be able to execute *.exe files too!