7 Replies Latest reply on Apr 15, 2016 12:26 PM by Ed Blair

    "Sometimes Required" Fields

    Ed Blair

      Wondering if anyone has run across this case.  Let me explain.

       

      We've got fields that are designated as required by setting "Allow NULL Values" to "No" in the ArcFM Properties Manager.  Most of the time this works exactly as we want -- it doesn't allow a feature to be created unless it has a non-NULL value.  But in *some* cases its possible to obtain the required value in the course of the edit operation, so we don't want to require a user to have to enter a value if we know we can get it for them.

       

      Was hoping that this could be done by an AutoUpdater that fires on create, grabs a value and stuffs in into the required field.  However, it seems that validation of required field values occurs before AutoUpdaters fire -- so we get a "Missing Required Field Value" message before the AutoUpdater has a chance to do its thing.

       

      We need to keep the field required.  We don't want to have to rely on QA after the fact to detect and generate an error if a required field is Null.

       

      Anyone know a way around this?   Any suggestions would be much appreciated.

       

      Thanks,

      Ed

        • Re: "Sometimes Required" Fields

          Ed,

          I'd try setting a default value for the field (eg. "nOtaRealvALue" or the MAX or MIN value for numeric data types) that the QA check can easily recognize if the field is not overwritten by the AU.

          Regards,

          Bill

          • Re: "Sometimes Required" Fields
            Cory Williams

            Hi Ed,

            is it possible to subtype the data?

             

            i.e. do you know when the fields are required and when they're not? You could have a subtype on that field, which could then have the field linked to a "Not Applicable" domain?

            That way in ArcFM Properties, specify that fields as Not Null that way you can always have a value, either Not Applicable or the user entered value.

             

            Cheers,

             

            Cory

            • Re: "Sometimes Required" Fields
              Neil Etheridge

              Hi Ed,

               

              You may be after a custom Field Property Strategy.  We implemented this for a client to allow required fields to be null when creating new or editing features in the attribute editor but not when QAQC is running ... so it ends up more like a "we suggest this is not null" field rather than a hard and fast not null field.  Happy to share the code if you think it might work for you.


              Cheers,

              Neil



               

                • Re: "Sometimes Required" Fields
                  Ed Blair

                  Neil -

                   

                  Sounds very interesting.  Since the time I asked the question we've decided

                  to take a somewhat different approach.  Basically more logic is placed in a

                  custom edit task where we have control of the proposed object

                  (IMMProposedObject).

                   

                  You definitely be interested in looking at the Field Property Strategy code

                  if you are able to share.

                   

                  Thanks again!

                  Ed

                   

                   

                  On Sun, Apr 10, 2016 at 6:29 PM, Neil Etheridge <

                  schneider-electric-admin@infrastructurecommunity.schneider-electric.com>

                    • Re: "Sometimes Required" Fields
                      Neil Etheridge

                      The strategy code is pretty straight forward ... just implement the IMMFieldProperty interface and add your logic to the Value method.  The logic should return 1 for true and 0 for false.  In my case I tried a few different methods but finally settled on a test to see if the QAQC dialog was the focused window on the screen.  Here is the code:

                       

                      using System;
                      using System.Runtime.InteropServices;
                      using System.Text;
                      
                      using ESRI.ArcGIS.Editor;
                      using ESRI.ArcGIS.esriSystem;
                      using ESRI.ArcGIS.Framework;
                      using ESRI.ArcGIS.Geodatabase;
                      using ESRI.ArcGIS.Geometry;
                      
                      using Miner.ComCategories;
                      using Miner.Interop;
                      
                      using SpikeTools.ArcFM;
                      
                      
                      
                      namespace SpikeTools.ArcFM.FieldPropertyStrategies {
                      
                          [ComVisible(true)]
                          [Guid("3DEA512B-83E0-388A-90E3-D858A08B3D85")]
                          public sealed class AttributeEditorOnlyFieldStrategy : IMMFieldProperty {
                      
                              #region Component Category Registration
                      
                              [ComRegisterFunction()]
                              static internal void Reg(string regKey) {
                                  FieldPropertyStrategy.Register(regKey);
                              }
                      
                              [ComUnregisterFunction()]
                              static internal void Unreg(string regKey) {
                                  FieldPropertyStrategy.Unregister(regKey);
                              }
                      
                              #endregion
                      
                      
                              [DllImport("user32.dll")]
                              static extern IntPtr GetForegroundWindow();
                      
                              [DllImport("user32.dll")]
                              static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
                      
                      
                      
                              //
                              // Constants
                              //
                      
                              private readonly string _toolName = "Attribute Editor Only";
                      
                      
                              //
                              // Private member variables
                              //
                      
                      
                      
                              //
                              // Constructor
                              //
                      
                              public AttributeEditorOnlyFieldStrategy() {
                      
                                  // nothing to do
                      
                              }
                      
                      
                      
                              //
                              // Public properties
                              //
                      
                              public string Name {
                      
                                  get {
                                      return _toolName;
                                  }
                      
                              }
                      
                      
                              //
                              // Public methods
                              //
                      
                              public int Value(IMMFieldManager fieldManager) {
                      
                                  // Always true
                                  //return 1;
                      
                                  // Always false
                                  //return 0;
                      
                      
                                  string focusedWindowName = GetActiveWindowTitle();
                      
                                  // Based on window name
                                  if (focusedWindowName == "Processing ArcFM QA/QC") {
                                      return 0;
                                  } else {
                                      return 1;
                                  }
                      
                              }
                      
                      
                      
                              //
                              // Private methods
                              //
                      
                              private string GetActiveWindowTitle() {
                      
                      
                                  const int nChars = 256;
                                  IntPtr handle = IntPtr.Zero;
                                  StringBuilder Buff = new StringBuilder(nChars);
                                  handle = GetForegroundWindow();
                      
                                  if (GetWindowText(handle, Buff, nChars) > 0) {
                                      return Buff.ToString();
                                  }
                      
                                  return null;
                      
                              }
                      
                          }
                      
                      }