private void AppendTdForField(StringBuilder table, Entity item, string field)
        {
            var path = XrmService.GetTypeFieldPath(field, item.LogicalName);

            table.AppendLine(string.Format("<td {0}>", tdStyle));
            table.Append(XrmService.GetFieldAsDisplayString(path.Last().Key, path.Last().Value, item.GetFieldValue(field)));
            table.AppendLine("</td>");
        }
Пример #2
0
        public static void AddRequiredQueryJoins(this XrmService xrmService, QueryExpression query, string source)
        {
            var typeFieldPaths   = xrmService.GetTypeFieldPath(source, query.EntityName);
            var splitOutFunction = source.Split(':');

            if (splitOutFunction.Count() > 1)
            {
                source = splitOutFunction.ElementAt(1);
            }
            var splitTokens = source.Split('.');

            if (typeFieldPaths.Count() == 1)
            {
                query.ColumnSet.AddColumn(typeFieldPaths.First().Value);
            }
            else
            {
                LinkEntity thisLink = null;

                for (var i = 0; i < typeFieldPaths.Count() - 1; i++)
                {
                    var lookupField = typeFieldPaths.ElementAt(i).Value;
                    var path        = string.Join(".", splitTokens.Take(i + 1)).Replace("|", "_");
                    if (i == 0)
                    {
                        var targetType    = typeFieldPaths.ElementAt(i + 1).Key;
                        var matchingLinks = query.LinkEntities.Where(le => le.EntityAlias == path);

                        if (matchingLinks.Any())
                        {
                            thisLink = matchingLinks.First();
                        }
                        else
                        {
                            thisLink             = query.AddLink(targetType, lookupField, xrmService.GetPrimaryKeyField(targetType), JoinOperator.LeftOuter);
                            thisLink.EntityAlias = path;
                            thisLink.Columns     = xrmService.CreateColumnSet(new string[0]);
                        }
                    }
                    else
                    {
                        var targetType    = xrmService.GetLookupTargetEntity(lookupField, thisLink.LinkToEntityName);
                        var matchingLinks = thisLink.LinkEntities.Where(le => le.EntityAlias == path);
                        if (matchingLinks.Any())
                        {
                            thisLink = matchingLinks.First();
                        }
                        else
                        {
                            thisLink             = thisLink.AddLink(targetType, lookupField, xrmService.GetPrimaryKeyField(targetType), JoinOperator.LeftOuter);
                            thisLink.EntityAlias = path;
                            thisLink.Columns     = xrmService.CreateColumnSet(new string[0]);
                        }
                    }
                }
                thisLink.Columns.AddColumn(typeFieldPaths.ElementAt(typeFieldPaths.Count() - 1).Value);
            }
        }
Пример #3
0
        public static string GetDisplayLabel(this XrmService xrmService, Entity targetObject, string token)
        {
            var fieldPaths    = xrmService.GetTypeFieldPath(token, targetObject.LogicalName);
            var thisFieldType = fieldPaths.Last().Key;
            var thisFieldName = fieldPaths.Last().Value;
            var displayString = xrmService.GetFieldLabel(thisFieldName, thisFieldType);

            return(displayString);
        }
Пример #4
0
        public static string GetDisplayString(this XrmService xrmService, Entity targetObject, string token, bool isHtml = false)
        {
            var    fieldPaths     = xrmService.GetTypeFieldPath(token, targetObject.LogicalName);
            var    thisFieldType  = fieldPaths.Last().Key;
            var    thisFieldName  = fieldPaths.Last().Value;
            string func           = null;
            var    getFieldString = token.Replace("|", "_");
            var    splitFunc      = getFieldString.Split(':');

            if (splitFunc.Count() > 1)
            {
                func           = splitFunc.First();
                getFieldString = splitFunc.ElementAt(1);
            }
            var displayString = xrmService.GetFieldAsDisplayString(thisFieldType, thisFieldName, targetObject.GetFieldValue(getFieldString), isHtml: isHtml, func: func);

            return(displayString);
        }
        private void AppendThForField(StringBuilder table, Microsoft.Xrm.Sdk.Entity firstItem, string field)
        {
            var path = XrmService.GetTypeFieldPath(field, firstItem.LogicalName);

            table.AppendLine(string.Format("<th {0}>{1}</th>", thStyle, XrmService.GetFieldLabel(path.Last().Value, path.Last().Key)));
        }