0

I have some problems with the fact that when I select a value in the dropbox, or rather steel a checkmark, then it is automatically reset.

[Serializable]
    public class KNRWCSAttributeExt : PXCacheExtension<CSAttribute>
    {
        public static bool IsActive() => true;

        #region UsrSchemaField

        [PXDBString(512, InputMask = "", IsUnicode = true)]
        [PXUIField(DisplayName = "Multi Schema Field")]
        //[PXUIVisible(typeof(Where<PX.CS.CSAttribute.controlType, Equal<CSAttribute.AttrType.giSelector>>))]
        [PXStringList(new string[] {null}, new string[] {""}, ExclusiveValues = false)]
        public virtual string UsrSchemaField { get; set; }

        public abstract class usrSchemaField : PX.Data.BQL.BqlString.Field<usrSchemaField>
        {
        }

        #endregion
    }

I assume that this is due to the fact that the event is triggered again and the array is filled over and over again. With the usual examples that are already described on stackoverflow it works, but my code does not work

Tell me please how I can get data into DropDown once so that I can then select and the value is not reset.

  public class KNRWCSAttributeMaintExt : PXGraphExtension<CSAttributeMaint>
    {
        public static bool IsActive() => true;

        protected virtual void _(Events.RowSelected<CSAttribute> e)
        {
            if (e.Row == null)
            {
                return;
            }

            var el = e.Row as CSAttribute;
                
            if (el.ControlType == CSAttribute.GISelector)
            {
                if (!string.IsNullOrEmpty(e.Row.ObjectName as string))
                {
                    Type objType = System.Web.Compilation.PXBuildManager.GetType(e.Row.ObjectName, true);
                    PXCache objCache = Base.Caches[objType];
                    var fields = objCache.Fields
                        .Where(f => objCache.GetBqlField(f) != null ||
                                    f.EndsWith("_Attributes", StringComparison.OrdinalIgnoreCase))
                        .Where(f => !objCache.GetAttributesReadonly(f).OfType<PXDBTimestampAttribute>().Any())
                        .Where(f => !string.IsNullOrEmpty((objCache.GetStateExt(null, f) as PXFieldState)?.ViewName))
                        .Where(f => f != "CreatedByID" && f != "LastModifiedByID")
                        .ToArray();

                    PXStringListAttribute.SetList<KNRWCSAttributeExt.usrSchemaField>(e.Cache, e.Row, fields, fields);
                }
            }
        }
    }

View

<asp:Content ID="cont2" ContentPlaceHolderID="phF" runat="Server">
    <px:PXFormView ID="form" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" DataMember="Attributes" Caption="Attribute Summary">
        <Template>
            <px:PXLayoutRule runat="server" StartColumn="True" ControlSize="M" LabelsWidth="SM" />
            <px:PXSelector ID="edAttributeID" runat="server" DataField="AttributeID" AutoRefresh="True" DataSourceID="ds">
                <GridProperties FastFilterFields="description" />
            </px:PXSelector>
            <px:PXTextEdit ID="edDescription" runat="server" AllowNull="False" DataField="Description" />
            <px:PXDropDown CommitChanges="True" ID="edControlType" runat="server" AllowNull="False" DataField="ControlType" />
            <px:PXCheckBox ID="chkIsInternal" runat="server" DataField="IsInternal" />
            <px:PXCheckBox ID="chkContainsPersonalData" runat="server" DataField="ContainsPersonalData" />
            <px:PXTextEdit ID="edEntryMask" runat="server" DataField="EntryMask" />
            <px:PXTextEdit ID="edRegExp" runat="server" DataField="RegExp" />
            <px:PXSelector ID="SchemaObject" runat="server" DataField="ObjectName" AutoRefresh="True" CommitChanges="true" />
            <px:PXDropDown ID="SchemaField" runat="server" DataField="FieldName" AutoRefresh="True"  CommitChanges="True"  />
            
            <px:PXDropDown ID="edRegExpMultiSelect" runat="server" AllowMultiSelect="true" DataField="UsrSchemaField" CommitChanges="True"/>
        </Template>
    </px:PXFormView>
</asp:Content>

2 Answers2

0

Having the field value disappear just means that the custom field was not correctly implemented. When the system can't select/persist a record or a field it disappears when control focus is lost.

The DAC field type appears to be wrong. Usually string list uses small codes of about 2 or 3 letters string with fixed size: [PXDBString(3, IsFixed = true)]

Since you are setting the list dynamically you don't need to define null string values in the DAC: [PXStringList]

You need to make sure that your event is always providing the expected code values. This can be checked by removing the conditions and using constants for the SetList method call: https://stackoverflow.com/a/38089639/7376238

Maybe you missed some steps like creating the field in the database table. You can test with an unbound PXString field instead of a PXDBString like in this example to see if that's the issue: https://stackoverflow.com/a/49907964/7376238

Hugues Beauséjour
  • 8,067
  • 1
  • 9
  • 22
  • This is the whole problem, which is why I asked for help, I removed the conditions and used constants to call the SetList method and everything works great, but as soon as I use my code, it does not work. I'm interested in how else I can implement my functionality. I tried the methods that you presented from the link, but they do not solve my problem – Артем Мазуров Mar 19 '21 at 19:02
0

Thanks for the help, I solved the problem by replacing "e.Row" with "null" in this line

before:

PXStringListAttribute.SetList<KNRWCSAttributeExt.usrSchemaField>(e.Cache, e.Row, fields, fields);

after:

PXStringListAttribute.SetList<KNRWCSAttributeExt.usrSchemaField>(e.Cache, null, fields, fields);