BPM: Storing values from a table and displaying them in an email

Hi everyone

I’m new to creating BPMs and writing custom code and I’m trying to figure something out here.

I’ve created a Data Directive BPM that sends out an email every time a part goes out of stock. I used PartBin.Update as my trigger and use custom code widget to see if stock is zero by adding all the quantities in all bins for that part and if 0 then send the email.

This works fine for the times when only one PartNum is involved as I can create a string variable to then use in the email but as soon as there are more (e.g. when shipping) then it obviously doesn’t work. I need to use an array or similar.

What I’m looking to do is loop through all the rows in ttPartBin; add up quantities and if total is zero then add that Part Number to a variable (array?) and then display the contents of that variable in the email.

I can’t seem to figure out what variable type to use (I assume I need to create a variable outside of the custom code widget so that I can access it in the email or is there a way of accessing variables that are defined in custom code in the email?

image

Thanks

A dataset would be ideal for this, but I don’t think you can iterate through that for the email widget.

Your best bet is to do the email in your code.

Here is an example of sending email with code:

https://www.epiusers.help/t/lets-share-useful-functions-sharing-is-caring/100371/2

Thanks Kevin

Before I go down that route, do you know where I can find out more about how to use datasets in custom code? Because surely I can just add the dataset to the email and it should show the full contents. I’ve done this with a tableset before and it works well.

Thanks

I believe that TableSets are just abstractions of System.Data.DataSet, you should be able to work with a DataSet the same way.

Thanks Kevin

My use of tablesets is limited to a BPM I created where I used a Fill Table By Query to add values to the tableset var and then dump that into an email.

I’m not sure how to use tablesets (and datasets) in custom code. I.e. I know how to create a foreach to loop through a database table (or a different tableset) but how do I now assign the values I want from the database to the tableset variable in the loop? I assume I need to add a new row to the tableset each time but just not sure how I do that.

Thanks

Yes, but that’ll look like :poop: :rofl:

As for a dataset, Look in this post, in the code part.


Also, you may be able to define a variable of a tableset you need there instead, have to add the right references and browse for it I think.

DataSets/TableSets are just collections of Table objects.

//Out of the box DS/TS classes will usually let you access the table as a subclass
var resultsTable = BaqTableSet.Results;
//You can also use the indexer
var yourTable = YourTableSet[0];
//If there is a TableName assigned, you can usually use that too.
var yourTable = YourTableSet["TableName"];

After that, you can foreach on yourTable or use lambda expressions to access specific records.

4 Likes

You could format your dataset as an html table. I did it before and the email turned out quite pretty :sparkler: : This would require c# coding. I’ll see if I can find my example of a grid, did it years ago.

1 Like

Does it need to be an instant alert or could you do this in a scheduled baq or function daily or even hourly?

Me too :grin:

Hey everyone

Thanks for all your help on this one. Finally managed to get it to work!

1 Like

What did you end up doing?

1 Like