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 :
Microsoft Dynamics CRM (Archived)

Filtered Records in Sub Grid in ms crm 2015 by using custom plugin

(0) ShareShare
ReportReport
Posted on by 790

 Hi 

 I have requirement  in lead entity form having  one custom field  name is "Course Title "(Text Field).

in this form  having a "course Sub-grid"  .In this sub grid filtered the course records  based on  search in Course

Tiltle filed. Example : If  the user search  enter a Title is   MBA in text filed  than all MBA Course records are displayed in sub grid.

public class LeadInterestCourse : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//Entity _StudentLead = new Entity("lead");
Entity _targetLeadIntrest = null;
string InterestedCoures=string.Empty;
if (context.Depth > 1)
{

}
// Check if the input parameters property bag contains a target of the create operation and that target is of type Entity.
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
// Verify that the entity represents a lead.
if (context.MessageName != MessageName.Create)
{
return;
}
else
{
try
{

//objtain the organization service reference
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
_targetLeadIntrest = (Entity)context.InputParameters["Target"];// Lead Entity as InPut Parametr


#region ToReterive all Couser based on Interested Course

InterestedCoures=_targetLeadIntrest.Attributes["mage_interestedcourse"].ToString();
var FetchCourseXml=
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='mage_leadinterestedcourses'>"+
"<attribute name='mage_leadinterestedcoursesid'/>"+
"<attribute name='mage_name'/>"+
"<attribute name='mage_source'/>"+
"<attribute name='createdon'/>"+
"<attribute name='mage_coursestatus'/>"+
"<attribute name='mage_course'/>"+
"<order attribute='mage_name' descending='false'/>"+
"<filter type='and'>"+
"<condition attribute='mage_name' operator='like' value='" + InterestedCoures + "'/>"+
"</filter>"+
"</entity>"+
"</fetch>";

EntityCollection InterestedCourseList = service.RetrieveMultiple(new FetchExpression(FetchCourseXml));
if (InterestedCourseList.Entities.Count>0)
{
foreach(Entity InCourse in InterestedCourseList.Entities)
{
if (InCourse.Contains("mage_source"))
{

}

if (InCourse.Contains("mage_coursestatus"))
{

}

if (InCourse.Contains("mage_course"))
{

}

if (InCourse.Contains("createdon"))
{

}

}
}
#endregion
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}

}
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    You need to use javascript to filter the subgrid. Please follow the below link to get an idea.

    crmpolataydin.wordpress.com/.../crm-2013-filtersubgrid

  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi Dynamics Group,

    In order to filter a subgrid dynamically on the content you enter on the screen, you should use javascript to apply the filter.

    On this blog: mahadeomatre.blogspot.nl/.../dynamically-filter-form-sub-grid-to.html you'll find a walkthrough to set up your own filter.

    You have to keep in mind that plugins only work after submission of a record (save action) and that plugins run in the server context. While the screen stuff (filtering etc) run in the client context (browser)

    I hope this will help you

    Bas

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    If I understand you correctly, what you are trying to do here is to Search the Values of related entity and for that you are using a plugin i.e. user will save every time after entering the value in the field Save and then on load you will bind the Data In Grid with Retrieve Multiple Message which is wrong.

    The solution you can go for is use client side script which triggers on change of the field and fetches the value and Displays it in a custom grid control (like JQ Grid)

    While implementing this solution you need to make sure the security role of the members and performance.

    1. If you have few records which you are trying to fetch and users have access to the records - You can use JavaScript to fetch and bind the values to the Grid.

    2. If you have whole lot of records or your users won't have access to the records you are trying to fetch you can use JavaScript to Trigger Custom Action, get the data and bind it in Custom Grid.

    Thanks,

    Abhinav Ranjan

  • naZir Profile Picture
    850 on at

    function FunctionName() {

       debugger;

       var lookupfield ;

       lookupfield = Xrm.Page.getAttribute("FieldName").getValue();

       if (lookupfield != null) {

           var grid = window.parent.document.getElementById("Grid View Name");

           var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";

           fetchXml += "<entity name='new_account_duplicate'>";

           fetchXml += "<attribute name='new_name' />";

           fetchXml += "<attribute name='new_married' />";

           fetchXml += "<attribute name='new_age' />";

           fetchXml += "<order attribute='new_name' descending='false' />";

           fetchXml += "<filter type='and'>";

           fetchXml += "<condition attribute='new_married' operator='eq' value='" + lookupfield + "' />";

           fetchXml += "</filter>";

           fetchXml += "</entity>";

           fetchXml += "</fetch>";

           grid.control.SetParameter("fetchXml", fetchXml);

           grid.control.Refresh();

       }

       }

    }

    generate fetch Xml code using Advance Find. Copy paste the code and modify it.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans