Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

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

$
0
0

 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);
}

}
}


Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>