LINQ Code - InvoiceDtl

Over to @aarong on that. It’s just a slightly altered version of his code, and I assumed there was more of it and InvoiceNum was already a set variable.

Few changes I would do:

I would use UpdateMaster and then you will have access to a built in pre-populated variable ipInvoiceNum, ipInvoiceLine, cTableName, cGroupID

The reason yours does not work probably is that you must be updating InvcDtl for the ttInvcDtlRow to have something populated, if you update a Misc Charge the BPM would only have ttInvcChrg or so.

1 Like

Can you example that in the current code?

var FreightTotal = (from invcDtl in Db.InvcDtl
                   where invcDtl.Company == Session.CompanyID && invcDtl.InvoiceNum == ipInvoiceNum
                   select invcDtl.DocTotalMiscCharge
                   ).DefaultIfEmpty(0).Sum();

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
  foreach (var invcDtl in (from InvcDtlRow in Db.InvcDtl
    where InvcDtlRow.Company == Session.CompanyID && InvcDtlRow.InvoiceNum == ipInvoiceNum
      select InvcDtlRow).ToList())
      {
        invcDtl["TotalFreight_c"] = FreightTotal;
      }
 Db.Validate();
 txScope.Complete();
}

This would trigger it on all tables being updated… you could do a wrapper around it and do

// im going to assume I got the table names right
if (cTableName == "InvcMisc" || cTableName == "InvcHead" || cTableName == "InvcDtl")
{
	var FreightTotal = (from invcDtl in Db.InvcDtl
	                   where invcDtl.Company == Session.CompanyID && invcDtl.InvoiceNum == ipInvoiceNum
	                   select invcDtl.DocTotalMiscCharge
	                   ).DefaultIfEmpty(0).Sum();

	using (var txScope = IceContext.CreateDefaultTransactionScope())
	{
	  foreach (var invcDtl in (from InvcDtlRow in Db.InvcDtl
	    where InvcDtlRow.Company == Session.CompanyID && InvcDtlRow.InvoiceNum == ipInvoiceNum
	      select InvcDtlRow).ToList())
	      {
	        invcDtl["TotalFreight_c"] = FreightTotal;
	      }
	 Db.Validate();
	 txScope.Complete();
	}
}

I hope that works… Sometimes I even check for changes in the PRE and then Enable a POST
Order Example

1 Like

Always check for available parameters via the context menu… :slight_smile: they help alot.

Still cannot get the field to update. What am I doing wrong?? :tired_face::tired_face:

If I had to guess the last item that stands out is select invcDtl.DocTotalMiscCharge it should be
select invcDtl.DocTotalMiscChrg

You should have also gotten an error, tho.

Hi Haso,

I changed this and it’s still not giving me a value.

have you read this post mate ?

1 Like

Anyone seen this before?

image
My BPM

Any ideas?

set what you want from the tttable as a parameter then use it in your condition in the original database table not the tt one

What do you mean?

replace the ttShipDtl by the Database ShipDtl

Got ya :smiley:

Sorry this thread has turned to something else I was also working on… I still haven’t been able to calculate that FreightTotal @hkeric.wci

You would have to do a trace… Perhaps GetShipments doesn’t invoke the Update or UpdateMaster (im assuming your creating invoices via GetShipments). I bet if you go to the Invoice add a new Misc Charge and save, it would trigger.

1 Like

image

Still giving me this…

This error is thrown up when they click Mass Shipment on Customer Shipment Entry - Off-topic of the current thread but similar problem.

i think that you need to set the parameter first then use it in the condition widget , is not it ?

1 Like

Some directives fire just once per call, even though the widgets are still there to allow you to structure the logic as though it’s firing for every record. When you get that combined situation, you get the “more than one record” error, because you’re asking it to do something to one row and it has several to choose from.

Usually, you either have to find a different trigger with the same records, or fall back on custom code and loop through the records in it.

1 Like