0
votes

I know that this is basic stuff and conditions, but I have an issue with a line that already exists in a service order. So we have Service Orders that will be imported into Acumatica and will already have a line. When in the Acumatica system someone will go to the Service Order screen (SD300100) and make the changes they wish after the import. In this case, they will change the Warranty Status, a custom field that we made, and it will change some values in the details and header. I have everything working, except for the first line that is brought in from the import on the detail line. So this order will come in with a line already inserted into the Labor tab. My issue is when we change the Warranty Status to warranty it should check another custom field's box called Warranty down in the detail line. I have this working for any newly inserted line but I can't get it with the already existing line. I have tried RowUpdated, RowUpdating, RowInserted, RowInserting on both the Header and Labor line data views. As well as the FieldUpdated, FieldUpdating and Selecting, on the header warranty selector and the Warranty checkbox in the details under the labor tab.

Here is my code:

public PXSelect<FSSODet,  Where<FSSODet.sOID, Equal<Current<FSSODet.sOID>>>> FSSODets;
    protected void FSServiceOrder_Usrwarrstat_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {

          var row = (FSServiceOrder)e.Row;
          if (row == null) return;
          FSSODet line = FSSODets.Current;
          if (line == null) return;
          if (line != null){
            FSServiceOrderExt rowExt = PXCache<FSServiceOrder>.GetExtension<FSServiceOrderExt>(row);
          if(rowExt == null)
          return;
          if (rowExt.Usrwarrstat == null) 
                return;

          if (rowExt.Usrwarrstat == "W"){ 
            cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);
            }
          }

        }

This was the last way I tried before going to here. If anyone has a different way, I can provide code for any of the methods metioned above, RowUpdated, RowUpdating, etc. Commit Changes is set to true on both fields.

In short, when the Usrwarrstat field is set to "W" in the Service Order header, I want the Usrwarrantydetail in the Labor Tab/Details to be set to true.

Update 1: So I used the 1st answer suggestion below and it did change the checkbox to checked, but it happens no matter what the status is. I only need it to be check if it is set to "W" or "P", the only the other option is "N" so I added a check to if it is set to "N" then it would be false. However, it is still saving it as true. Here is the updated code:

public PXSelect<FSSODetService,  Where<FSSODetService.sOID, Equal<Current<FSSODetService.sOID>>>> FSSODets;
    protected void FSServiceOrder_Usrwarrstat_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
    {

      var row = (FSServiceOrder)e.Row;
      if (row == null) return;
      FSSODetService line = FSSODets.Current;
      if (line == null) return;
      if (line != null){
        FSServiceOrderExt rowExt = PXCache<FSServiceOrder>.GetExtension<FSServiceOrderExt>(row);
      if(rowExt == null)
      return;
      if (rowExt.Usrwarrstat == null) 
            return;

      if (rowExt.Usrwarrstat == "W" || rowExt.Usrwarrstat == "P"){ 
        FSSODets.Cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);
        }
      if (rowExt.Usrwarrstat == "N"){
        FSSODets.Cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, false);
        }
      }

    }

        }
1

1 Answers

0
votes

Overall the logic looks good. There's a Cache object mismatch that could prevent SetValueExt from working:

// When this event handler is called by the framework
// PXCache cache object will be of type  FSServiceOrder
// because the event is bound on FSServiceOrder DAC
protected void FSServiceOrder_Usrwarrstat_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

When you call SetValueExt you should use a cache object of matching type:

// cache reference is of type FSServiceOrder but we want to modify FSSODetExt DAC field
cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);

// With extensions you have to use the base DAC cache
// you already declared a DataView on FSSODet so you can use it's cache reference
FSSODets.Cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);

Besides the DAC cache reference mismatch there's a possibility that you do successfully modify the field value but another event handler/mechanism modifies it again after you. To check that you can declare a event handler on the target field, put a breakpoint in it and debug it using visual studio debug stack trace window. The stack trace will show which methods lead to the field modification.

protected void FSSODet_Usrwarrantydetail_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

Also make sure Usrwarrstat field has the CommitChanges = True property set in the ASPX file or else modifying the field on screen won't execute the associated FieldUpdated event handler.