Skip to main content

Here is my use-case: 

a user changes a drop-down value (UsrShipStatus)

I need that value to update another field (UsrDfltWarehouse), this field will then create a dialogue box where I need to select “OK”

This then calls the function private void setWarehouses(POOrder row).

Below is the code in use here, I’m just lost on how to even interact with a dialogue box, or if I even need to (see comments below).

 


 

  public class POOrderEntry_Extension:PXGraphExtension<POOrderEntry>
  {
  
    protected void POOrder_UsrShipStatus_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
    {
      if (InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
      var row = (POOrder)e.Row;
      if (row == null) return;

      POOrderExt pOOrderExt = cache.GetExtension<POOrderExt>((object)row);

      if (pOOrderExt.UsrShipStatus == "POE")
      {
        const string CUSTOMER_TYPE = "C";
                
        /* PORT LB - Port Long Beach */
        const int PORT_LB_PROD = 443;


        row.ShipToBAccountID = PORT_LB_PROD;
        row.ShipDestType = CUSTOMER_TYPE
        row.UsrDfltWarehouse = “DIRECT”

// ^^THIS IS THE CODE THAT WILL EXECUTE THE DIALOGUE BOX BELOW, maybe I should just call SetWarehouses(row) here to bypass the dialogue check below?
      }
    }
          
    protected void POOrder_UsrDfltWarehouse_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
    {
      string msg = "Apply warehouse change to all Order Lines?";
      var row = (POOrder)e.Row;
      WebDialogResult result = Base.Transactions.Ask("Information", msg, MessageButtons.OKCancel);
      if (result == WebDialogResult.OK)
      {
        setWarehouses(row);
      }
    }
    

//This set of code applies the warehouse to all the PO Lines based on the warehouse value in the UsrDfltWarehouse field
    private void setWarehouses(POOrder row)
    {
      POOrderExt PoExt = PXCache<POOrder>.GetExtension<POOrderExt>(row);
      var site = PoExt.UsrDfltWarehouse;
      foreach (POLine line in Base.Transactions.Select())
      {
        line.SiteID = site;
        Base.Transactions.Update(line);
        Base.Transactions.View.RequestRefresh();
      }
    }

 

I know this is a bit of a read, but I’ve never worked with dialogue box answers in the code editor. I know how it’s done on import scenarios, but not here. Any help or links would be greatly appreciated.

THANK YOU EVERYONE!

Hi @Michaelh ,

You can raise the POOrder_UsrDfltWarehouse_FieldUpdatedFieldupdated  event in POOrder_UsrShipStatus_FieldUpdated with the below syntax

cache.RaiseFieldUpdated<POOrder.usrShipStatus>(row,rowext.UsrDfltwarehouse);


I'm kinda lost on what you're asking. Is the code you have not working?


Maybe I’m mis-understanding. When I update the value with the line:

row.UsrDfltWarehouse = “DIRECT”

I think it will trigger:
 

protected void POOrder_UsrDfltWarehouse_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

This segment creates a dialogue box. I don’t know how to tell that dialog box “OK” to get the event to trigger where all the PO Lines are updated to the warehouse that was set on row.UsrDfltWarehouse in the first code segment.

 


I would attempt to just call the method directly and see if the dialog is an issue. If it is, you may be able to write an override of that method and catch the dialog exception to prevent it in this situation. But no use doing that till we know if it's a problem.


Hi @Michaelh 

 

It looks that when you assign a value to UsrDfltWarehouse it does not trigger any events (incl. FieldUpdated).

So I would suggest call SetValueExt instead

cache.SetValueExt<POOrderExt.usrDfltWarehouse>(row, “DIRECT”);


 


I don't believe he wants to call it. He just wants the method to execute, and if it does get called, he's not sure how to close it appropriately. To be honest, since it's in existing code, I'm not sure how to either. Which is why I'm hoping it doesn't get called. He can just call the method directly.


@darylbowman - I did just as you say, and bypassed the “Field Updated” trigger. Thanks everyone!


Reply