private PXFilterRow CheckEmployeeInWorkgroup(EPEmployee employee, EPRuleBaseCondition rule)
        {
            var filter = new PXFilterRow()
            {
                DataField = typeof(EPCompanyTree.description).Name,
                Condition = (PXCondition)rule.Condition.Value,
                Value     = rule.Value,
                Value2    = null
            };

            PXSelectBase <EPCompanyTree> select = new PXSelectJoin <EPCompanyTree,
                                                                    InnerJoin <EPCompanyTreeMember, On <EPCompanyTree.workGroupID, Equal <EPCompanyTreeMember.workGroupID> > >,
                                                                    Where <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> >,
                                                                           And <EPCompanyTreeMember.active, Equal <True> > > >(this);

            int startRow  = 0;
            int totalRows = 0;
            var result    = select.View.Select(null, new object[] { employee.UserID }, null, null, null, new PXFilterRow[] { filter }, ref startRow, 1, ref totalRows);

            return(new PXFilterRow()
            {
                DataField = typeof(EPEmployee).Name + "__" + typeof(EPEmployee.bAccountID).Name,
                Condition = result.Count > 0
                                        ? PXCondition.ISNOTNULL
                                        : PXCondition.ISNULL,
                Value = null,
                Value2 = null
            });
        }
        protected PXFieldState CreateFieldStateForFieldName(object returnState, Type entityType, Type gType, string viewName, string cacheName, int?fieldLength, EPRuleBaseCondition condition)
        {
            List <string> allowedValues = new List <string>();
            List <string> allowedLabels = new List <string>();
            List <string> uniqueLabels  = new List <string>();

            if (entityType != null)
            {
                Type cachetype = GraphHelper.GetType(cacheName);
                if (cachetype == null)
                {
                    return(null);
                }
                if (condition != null)
                {
                    string fieldName = condition.FieldName;
                    if (!string.IsNullOrEmpty(fieldName))
                    {
                        PXFieldState state = GetPXFieldState(cachetype, fieldName);
                        if (state == null)
                        {
                            Rules.Cache.SetStatus(condition, PXEntryStatus.Updated);
                            Rules.Cache.RaiseExceptionHandling <EPRuleCondition.fieldName>(condition, fieldName, new PXSetPropertyException(Messages.FieldCannotBeFound, PXErrorLevel.Error));
                        }
                    }
                }
                Dictionary <string, string> fields = new Dictionary <string, string>();
                foreach (CacheEntityItem c in
                         EMailSourceHelper.TemplateEntity(this, viewName,
                                                          entityType.FullName,
                                                          gType != null ? gType.FullName : null, false))
                {
                    fields[c.SubKey] = c.Name;
                }

                Action <string, string> addValueLabel = (value, label) =>
                {
                    allowedValues.Add(value);
                    allowedLabels.Add(label);
                    uniqueLabels.Add(label);
                };
                foreach (var item in fields.OrderBy(i => i.Value))
                {
                    if (!item.Key.EndsWith("_Attributes") && item.Key.Contains('_'))
                    {
                        continue;
                    }

                    var attr = this.Caches[cachetype].GetAttributes(null, item.Key);

                    var value = item.Value;

                    if (attr != null)
                    {
                        var timeListAttribute = attr.FirstOrDefault(a => a is PXTimeListAttribute) as PXTimeListAttribute;
                        var intAttribute      = attr.FirstOrDefault(a => a is PXIntAttribute) as PXIntAttribute;
                        if (timeListAttribute != null && intAttribute != null)
                        {
                            value += " (" + PXLocalizer.Localize("Minutes") + ")";
                        }
                    }

                    if (!uniqueLabels.Contains(value))
                    {
                        addValueLabel(item.Key, value);
                    }
                    else
                    {
                        string label = string.Format("{0} - {1}", item.Key, value);
                        addValueLabel(item.Key, label);
                    }
                }
            }

            return(PXStringState.CreateInstance(returnState, fieldLength, null, _FIELDNAME_STR, false, 1, null,
                                                allowedValues.ToArray(), allowedLabels.ToArray(), false, null));
        }
        protected PXFieldState CreateFieldStateForFieldName(object returnState, string entityType, string graphType, string cacheName, EPRuleBaseCondition condition = null)
        {
            Type type = GraphHelper.GetType(entityType);

            if (type != null)
            {
                Type gType = EntityHelper.GetPrimaryGraphType(this, type);
                if (!String.IsNullOrEmpty(graphType))
                {
                    gType = GraphHelper.GetType(graphType);
                }
                string viewName = null;
                if (gType != null)
                {
                    foreach (
                        CacheEntityItem view in
                        EMailSourceHelper.TemplateEntity(this, null, type.FullName, gType.FullName))
                    {
                        if (view.SubKey == cacheName)

                        {
                            viewName = view.Key;
                            break;
                        }
                    }
                }
                return(CreateFieldStateForFieldName(returnState, type, gType, viewName, cacheName, EPRuleCondition.FieldLength, condition));
            }
            return(PXStringState.CreateInstance(returnState, EPRuleCondition.FieldLength, null, _FIELDNAME_STR, false, 1, null,
                                                (new List <string>()).ToArray(), (new List <string>()).ToArray(), false, null));
        }