Data Directive on RcvHead custom code query not showing results new rows on RcvDtl

Hi all, I am writing a data directive to email when receipts are entered.

foreach (var bpm_row in ttRcvHead) {
  int po_num = (int) bpm_row["PONum"];
  string company = (string) bpm_row["Company"];
  var receipt_date = bpm_row["ReceiptDate"];
  var receive_person = (string) bpm_row["ReceivePerson"];
  bool received = (bool) bpm_row["Received"];
  
  if (!received) {
    return;
  }

  var lines_on_po = (from rcv_dtl in Db.RcvDtl where rcv_dtl.PONum == po_num select rcv_dtl);
  
  string _out = "";
  
  foreach (var sql_row in lines_on_po) {
    var r_ps = sql_row["PackSlip"];
    var r_po = "Line " + sql_row["POLine"] + ", Release " + sql_row["PORelNum"];
    var r_location = sql_row["WareHouseCode"] + "/" + sql_row["BinNum"];
    var r_operation = sql_row["ReceivedTo"];
    var r_our_qty = sql_row["OurQty"];
    var r_part_num = sql_row["PartNum"];
    var r_part_description = sql_row["PartDescription"];
    _out += $"---- {r_ps} ----\n    {r_po}\n    Location: {r_location}\n    Quantity: {r_our_qty}\n    Part Number: {r_part_num}\n    Part Description: {r_part_description}\n    Receive Person: {receive_person}\n    Receipt Date: {receipt_date}\n  \n  ";
  }
  
  // email '_out'
}

This returns no rows, but since it’s a data directive shouldn’t the rows be in the database by this point? I am able to get rows to show up if I expand the search to other PO numbers, so I know the code is functional. Any help would be fantastic. Thanks!

more context please.

In trans, standard, table etc

It’s a standard data directive, on the RcvHead table

1 Like

I am not a coder I do everything with widgets :smirk: but I think I understand what this is trying to do.

I just wanted to point out PONum is not a required field on RcvHead and can be 0. Maybe that helps.

var lines_on_po = (from rcv_dtl in Db.RcvDtl where (DateTime) rcv_dtl.ReceiptDate == (DateTime) receipt_date select rcv_dtl);

This code returns all the receipts from today, excluding the new rows. I need to know the part and quantity of the PO receipt, but the ttRcvHead fields are limited.

Any help is appreciated

It really depends on the data you want in your email, but you probably don’t even need RcvHead. A new record in RcvDtl is a pretty good indication something has been received, and it has data like part number, received quantity, etc, right there. Unless you wanted to do something semi-tricky like show the vendor name this should be pretty simple.

Looking forward to the thread you create in a few weeks asking how to turn this off because people are complaining about getting too many emails. :wink::stuck_out_tongue_winking_eye:

1 Like

I can use the following:

string text = "";
foreach (var row in ds.RcvDtl) {
  var r_po = row["PONum"];
  var r_tran_type = row["TranType"];
  var r_packslip = row["PackSlip"];
  var r_arrived_date = row["ArrivedDate"];

but many of the fields I want are not filled for some reason.

  var s = JsonConvert.SerializeObject(row);
{
	"ColumnNames": 0,
	"Company": "200",
	"VendorNum": 186,
	"PurPoint": "",
	"PackSlip": "testing3",
	"PackLine": 0,
	"Invoiced": false,
	"InvoiceNum": "",
	"InvoiceLine": 0,
	"PartNum": "",
	"WareHouseCode": "",
	"BinNum": "",
	"OurQty": 0.0,
	"IUM": "",
	"OurUnitCost": 0.0,
	"JobNum": "",
	"AssemblySeq": 0,
	"JobSeqType": "",
	"JobSeq": 0,
	"PONum": 5026,
	"POLine": 0,
	"PORelNum": 0
}

I need to access the part information in my code to email out.

I don’t know if it matters here, but you are doing that inside a for loop.
That will exit the whole bpm.

If you want to exit the bpm, that’s fine, use return;
If you want to exit the for loop altogether use break;
If you want to short circuit and go to the next record in the for loop, use continue;

1 Like

Where are you accessing that from?

Anyway, it’s certainly possible that all the data you want is not written yet.

Just because the head is written, doesn’t mean all the detail rows are yet.


So let’s start over, what are the exact conditions you want to occur in real life where you want this email to go out?

2 Likes

When a new receipt entry is filled & received is checked, and the part is in our warehouse, an email should be sent out containing the contents of the received items including part descriptions

This does matter- thanks, but it won’t fix my issue unfortunately.

1 Like

Are you wanting an email for each detail record?

1 Like

Ideally it would be combined, but it’s not my inbox :joy:

1 Like

To me, this sounds better suited for a BAQ report that is processed on a schedule. Pull all the tables and fields you want into a BAQ, make a report, set it up with APR and then set up a schedule to run it. Emails get sent out to the target audience with a summary of what’s been received in the last week/day/hour/minute… whatever interval you choose.

Unless you need split second alerts, this seems a little easier to manage.

… but that’s coming from a “no-coder”.

2 Likes

Hulk Hogan Handshake GIF

2 Likes

I’m having similar thoughts.

If more real time is needed, we could also schedule a function to run a few minutes after receipt, to guarantee everything is written. (If that is in fact one of the issues here.)

Y’all know widgets are code right?

Just Asking Pulp Fiction GIF

3 Likes

Yeah, it would have to be shortly after receiving. If certain parts come in, we may want to begin work using those items immediately and the email would save time

1 Like

I see it as the whole “Magic” vs “Science” argument.

You know the science… but for me… I just want to believe in Magic!

Arrested Development Dancing GIF

Me too, but I was more referring to you are the coder.

You code, but with widgets.

1 Like

I’ll be back, see if we can work something up.