Trying to Copy data from OrderDtl.QuoteNum to UD field OrderHed.QuoteNum_c and show on Order Entry Screen on load

,

// 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.

Add these in above the condition check:

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.

Here is all in one code block (should work but has not been tested):

// 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?)

Any ideas?

And you tried creating a Data Directive on OrderDtl table correct?

Sorry about that. I tried it on the OrderHed.

I created in Data Directive: OrderDtl - In-Transaction.

The code did not error out this time but it doesn’t seem to do anything when I open an existing Sales Order.

I then changed the qty on the line for it and it did do the copy to database plus the fill in on the screen.

My problem is it doesn’t run when you open the sales order.

Am I missing something?

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’.

So I assume I have to move back to the method directive.

Will this code translate to that or do I need to start over again?

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!

1 Like