0
votes

Currently, the Selector displays some value on exception and displays a red colored error message but I want to clear the field and show the red error message.Below is the line of code I have written.

    throw new PXSetPropertyException<CRCase.caseClassID>("Incorrect Case Class for Contract");
2

2 Answers

2
votes

While not related to PXSetPropertyException I'm sharing this way of clearing errors and warning using 'null' as it may be useful to other looking to clear error and warning symbols:

PXUIFieldAttribute.SetWarning<DAC.Field>(cache, dacRecord, null);
PXUIFieldAttribute.SetError<DAC.Field>(cache, dacRecord, null);

You can achieve similar results to clear all records error with:

PXUIFieldAttribute.SetWarning<DAC.Field>(cache, null, null);
PXUIFieldAttribute.SetError<DAC.Field>(cache, null, null);

EDIT:

Check if using that pattern instead of PXSetPropertyException could help. The key is to call SetWarning/SetError on each call with either null (no error) or with the error message.

protected virtual void DAC_FIELD_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
   DAC dacRecord = e.Row as DAC;

   if (dacRecord != null)
   {
      bool isError = [your error condition];
      
      if (isError)
      {
         dacRecord.Field = null; 
      }

      PXUIFieldAttribute.SetError<DAC.field>(sender, 
                                             dacRecord, 
                                             isError ? "Error Message" : null);
   }
}
0
votes

Without knowing which event you are in I can guess you are in field verifying. You can set e.NewValue = to the old value or null before the exception. The old value will be in e.Row where e is PXFieldVerifyingEventArgs.

Edit: Using a Field Updated event is too late as the value is already committed to cache. You should use field verifying or field updating to cancel the value if the value is incorrect. Field Verifying sounds like you what you should use to check the entered value.

Here is an example using field verifying in a graph extension to reset the entered value back to the previous value or just change the example to always null the entered value...

public virtual void CRCase_CaseClassID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying del)
{
    del?.Invoke(cache, e);

    //Check for some condition...

    e.NewValue = ((CRCase) e.Row).CaseClassID; /* Reset to previous value, otherwise set to null to clear entered value  */
    throw new PXSetPropertyException<CRCase.caseClassID>("Incorrect Case Class for Contract");
}