web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

create complex view with filter using plugin in crm 365

(0) ShareShare
ReportReport
Posted on by 2,667

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

I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    Hello Jharana,

    Please refer below Blogs which will help you to implement your requirement.

    www.dynamicpeople.nl/.../

    community.dynamics.com/.../create-view-using-dynamic-field-entries

    Thank you,

    Amit Katariya

  • Jharana Baliyar Singh Profile Picture
    2,667 on at

    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

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    can you share error log or file?

  • Jharana Baliyar Singh Profile Picture
    2,667 on at

    Hi Amit,

    Please find the vs error

    vserror.png

    vserror2.PNG

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    Hello

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    Line Number 28 it should be Query not query

    pastedimage1653652084119v1.png

    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.

    pastedimage1653653113494v4.png 

    Line Number 96:

    pastedimage1653652709541v2.png

    Line 112: also after this you have not provided the foreach.

    pastedimage1653652932098v3.png

    Function name is not correct.

    pastedimage1653653283874v5.png

    Thank you,

    Amit Katariya

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans