Announcements
Hi All,
I need to show view in view page in crm 365 using plugin retrieve multiple.
Is any link or code to show complex view in crm ?
Thanks,
Jharana
There are some Mistakes like variable name is not correct and function name is not correctly declared. please check out this and try to add tracing in between code so that you will know how much code is working.
Line Number 28 it should be Query not query
context.InputParameters["Query"] = modifier.ModifyQuery(query);
Line number 30 : Remove static from it. it will be private QueryBase.
Line number 63:
Not present in the article.
Line Number 96:
Line 112: also after this you have not provided the foreach.
Function name is not correct.
Thank you,
Amit Katariya
Hello
Hi Amit,
Please find the vs error
can you share error log or file?
Hi Amit,
I am following the 1st link for this requirement but i am getting error in vs code.
I am using below complete code but getting error in vs.Is there any wrong in below code?
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ConditionalFiltering
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
var query = GetQuery(context);
if (query == null)
{
return;
}
var factory = new QueryModifierFactory(context, service, tracingService);
var modifier = factory.GetModifier(query);
context.InputParameters["query"] = modifier.ModifyQuery(query);
}
private static QueryBase GetQuery(IPluginExecutionContext context) => (!context.InputParameters.Contains("Query") ? null : (QueryBase)context.InputParameters["Query"]);
}
public class QueryModifierFactory
{
private readonly IPluginExecutionContext _context;
private readonly ITracingService _tracingService;
private readonly IOrganizationService _service;
public QueryModifierFactory(
IPluginExecutionContext context,
IOrganizationService service,
ITracingService tracingService)
{
_context = context;
_tracingService = tracingService;
_service = service;
}
public IQueryModifier GetQuery(QueryBase query)
{
if (query is FetchExpression)
{
var fe = query as FetchExpression;
if (fe.Query.Contains(TPAInvestorApprovalQueryModifier.ModifierFlag))
{
return new TPAInvestorApprovalQueryModifier(_context, _service, _tracingService);
}
}
_tracingService.Trace($"No modifier found, returing default modifier.");
return new NoModificationQueryModifier();
}
internal object GetModifier(QueryBase query)
{
throw new NotImplementedException();
}
}
public class NoModificationQueryModifier : IQueryModifier
{
/* public QueryBase ModifyQuery(QueryBase query)
{
return query;
}*/
}
public class TPAInvestorApprovalQueryModifier : IQueryModifier
{
internal static string ModifierFlag = "TPA/Investor Approval";
private readonly IPluginExecutionContext _context;
private readonly ITracingService _tracingService;
private readonly IOrganizationService _service;
public TPAInvestorApprovalQueryModifier(
IPluginExecutionContext context,
IOrganizationService service,
ITracingService tracingService)
{
_context = context;
_tracingService = tracingService;
_service = service;
}
}
public QueryBase ModifyQuery(QueryBase query)
{
FetchExpression fetchQuery = query as FetchExpression;
if (fetchQuery == null) return query;
//object _context = null;
// var tags = GetTagsForUser(_context.InitiatingUserId);
XDocument fetchXMLDoc = XDocument.Parse(fetchQuery.Query);
var entityElement = fetchXMLDoc.Descendants("entity").FirstOrDefault();
var entityName = entityElement.Attributes("name").FirstOrDefault().Value;
if (entityName != "quote") return query;
var filterElements = entityElement.Descendants("filter");
filterElements
.Descendants("condition")
.Where(c => c.Attribute("attribute").Value.Equals("wcl_tpacommission") && c.Attribute("value").Value.Equals(ModifierFlag))
.ToList()
.ForEach(x => x.Remove());
object lexicon = null;
var tagcondition = new XElement("Condition",
new XAttribute("attribute", lexicon.CallReport.Tag),
new XAttribute("operator", "in"));
/*foreach (var tag in tags)
{
tagcondition.Add(new XElement("value", tag.ToString()));
}*/
entityElement.Add(
new XElement("link-entity",
new XAttribute("name", "dp_callreport_dp_tag"),
new XAttribute("from", "dp_callreportid"),
new XAttribute("to", "dp_callreportid"),
new XAttribute("link-type", "inner"),
new XAttribute("intersect", "true"),
new XAttribute("filter", tagcondition)));
//object _tracingService = null;
// _tracingService.Trace(fetchXMLDoc.ToString());
return new FetchExpression(fetchXMLDoc.ToString());
}
/*private object GetTagsForUser(object initiatingUserId)
{
throw new NotImplementedException();
}*/
}
Thanks,
Jharana
Hello Jharana,
Please refer below Blogs which will help you to implement your requirement.
community.dynamics.com/.../create-view-using-dynamic-field-entries
Thank you,
Amit Katariya
André Arnaud de Cal...
293,296
Super User 2025 Season 1
Martin Dráb
232,093
Most Valuable Professional
nmaenpaa
101,156
Moderator