0
votes

I have a checkbox on a DAC extension to the BAccount that I want to use to set a checkbox on Case when a customer is selected. Here is what the checkbox looks like on the Business Account screen.

Here is the field on the Case screen that I want to set when the customer is selected.

I found a stack overflow question where a couple of custom fields on a customer screen were to be copied to custom fields on a sales order. I have tried to substitute my fields into the code but I haven't been able to make it work.

Here is what I have tried. I'm not sure what I am missing.

protected void CRCase_CustomerID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
  var crcase = e.Row as CRCase;
  if (crcase.CustomerID != null)
  {
    var customer = PXSelectorAttribute.Select<CRCase.customerID>(sender, crcase) as BAccountR;
    if (customer != null)
    {
      var customerExt = customer.GetExtension<BAccountExt>();
      var crcaseExt = crcase.GetExtension<CRCaseExt>();
      crcaseExt.UsrContractCustomer = customerExt.UsrSage100;
    }
  }
}

I do not understand why BAccountR is used instead of just BAccount. Neither works right now.

I solved the issue by combining are response I received on an earlier post. I modified the last two line as follows:

      var customerExt = customer.GetExtension<BAccountExt>();
      //var crcaseExt = crcase.GetExtension<CRCaseExt>();
      //crcaseExt.UsrContractCustomer = customerExt.UsrSage100;
      sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, customerExt.UsrSage100 != null);

So here is the final issue that I need to resolve. The checkbox I used on the Business Account screen opens a new tab that displays custom fields. These custom fields are an extension of the BAccount DAC called DSDSage100. It is similar to the extension of the BAccount called Customer. In the DSDSage100 extension there is a field called UsrContractCustomer. That is the field that I want to read and set the Case field to the same value. Here is what the Sage 100 Tab looks like. I have a using directive for my project but I can't find the right reference to the DSDSage100 extension.

      var customerExt = customer.GetExtension<DSDSage100>();
      sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, customerExt.UsrContractCustomer != null);
1
Can you describe from your example what is not working? is customer, customerExt, crcaseExt, or USrSage100 null? The reason for BAccountR is that selector used on the field is using that DAC. (which inherits from BAccount). Maybe there is an issue trying to get an extension from an inherited DAC. - Brendan
Validation fails stating the type or namespace 'DSDSage100' (or 'DSDSage100Settings') could not be found. The UsrSage100 field I originally tested with is a direct extension of the BAccount DAC. DSDSage100 is a separate table that extends the BAccount like Customer does. I'm unclear how to reference it or what the using directive would be. - John Wiles

1 Answers

0
votes

Acumatica provided the answer. While I "extended the BAccount DAC" with my custom table (DSDSage100, similar to the way Customer is an extension of the BAccount DAC), it is it's own DAC. The solution was:

DSDSage100 mydac = PXSelect<DSDSage100, Where<DSDSage100.bAccountID, Equal<Required<DSDSage100.bAccountID>>>>.Select(Base, crcase.CustomerID); 
sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, mydac.UsrContractCustomer != null);

Thanks for the help and support.