// Field Filled? Based on you saying they're going to free form type in there this should be a nvarchar(x) field so compare it with a known set string of "NotFilled" otherwise assume field is filled.
this.bFieldNotFilled=((Db.OrderHed.Where( r=>r.Company==Session.CompanyID && r.OrderNum == this.iOrderNum ).Select(r=>r.QuoteNum_c).FirstOrDefault() ?? "Not Filled")=="Not Filled");
I just define the variables in the DD for debug purpose and readability my mistake on the above I forgot the OrderHed table is not part of the recordset. This should get you a boolean variable you can check against.
EDIT: *Note to above code block, you will not need to grab the this.iOrderNum in the setter block as the value has been set to check the OrderHed table field for data.
// Init variables
this.bFieldNotFilled=false;
this.iOrderNum=0;
this.iQuoteNum=0;
// Grab a row to set fields with
var ttOrderDtlRow = Epicor.Customization.Bpm.EnumerableExtensions.GetSingleRow(ttOrderDtl, "ttOrderDtl");
this.iOrderNum=ttOrderDtlRow.OrderNum; // Set our variable
// Based on you saying they're going to free form type in there this should be a nvarchar(x) field so compare it with a known set string of "NotFilled" otherwise assume field is filled.
this.bFieldNotFilled=((Db.OrderHed.Where(r => r.Company == Session.CompanyID && r.OrderNum == this.iOrderNum).Select(r => r.QuoteNum_c).FirstOrDefault() ?? "Not Filled")=="Not Filled"); // Set Variable
// check if OrderHed Field is not Filled and set our variable.
if (this.bFieldNotFilled)
{
this.iQuoteNum=ttOrderDtlRow.QuoteNum; // Set our variable
if ( this.iQuoteNum > 0 ) // Skip if no quote also
{ // Got one and field is not already filled so let's set it.
using (var txScope = IceContext.CreateDefaultTransactionScope())
{ // If you want you can add try catch and message blocks for better visibility.
foreach(var oh in Db.OrderHed.With(LockHint.UpdLock).Where(oh => oh.Company == Session.CompanyID && oh.OrderNum == this.iOrderNum))
{
oh.QuoteNum_c = this.iQuoteNum.ToString(); //Set custom ud field
}
Db.Validate(); // Validate our Save to DB
txScope.Complete(); // Finish with our txScope
}
}
}
Sorry it has taken a bit to get back to this. Boss had me pulled onto something else.
I copied your code and put in the Data Directive and got 3 errors.
The name âttOrderDtlâ does not exist in the current context
âTSourceâ does not contain a definition for âOrderNumâ and no accessible extension method âOrderNumâ accepting a first argument of type âTSourceâ could be found (are you missing a using directive or an assembly reference?)
âTSourceâ does not contain a definition for âQuoteNumâ and no accessible extension method âQuoteNumâ accepting a first argument of type âTSourceâ could be found (are you missing a using directive or an assembly reference?)
Yes, it was âmis-understoodâ that this was for new order creation from a quote. And the trigger is on the âUpdateâ BO and that wont trigger on a simple open only after an âupdateâ.
If you wish this to go out and retroactively set that field I would think a uBAQ would do it for you, because even GetList MD would only update the records on access, similarly update does on any change/creation to the record if the field is empty.
You can also add a MD to GetList to update if the record is accessed. Possibly in a pre-processing directive if you are not looking for fully retroactive update to all the OrderHed records.
Really many ways to do what you are wanting, but I would think a Advanced BPM UBAQ would do the trick to update your open? old non voided? all? I really donât know what your plan is in truth most of the discussion from my perspective has been specifically tailored to update {Copy data from OrderDtl.QuoteNum to UD field} your field when the OrderDtl record is available to update the OrderHed table.
I am looking for this to work on order creation, yes.
But also would like to to update all old orders on if they were generated from a quote.
If you say an updateable BAQ is my best bet to update the old ordres, then I will put some time into that and use the data directive that you have created.
If I get stuck on the updateable BAQ portion, I will create a new thread on here.
I truly appreciate your help on this and thank you from the bottom of my heart for your generous help that you didnât have to give.
I hope someday to know enough to turn around and help someone myself!