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

Plugin is not working while update the record

$
0
0

Hi,

I wrote the plugin for  Assigning the leads to specific users based on conditions while create the lead.when I create the records its working fine but when I update the field value it's not working. earlier it works fine.but I am not able to findout what went wrong in the solution? can any one suggest. please

here is my code

 IOrganizationServiceFactory servicefactory =
                               (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                        IOrganizationService client = servicefactory.CreateOrganizationService(context.UserId);
                        _leadID = entity.Id;
                        if (((OptionSetValue)entity.Attributes["country_value"]).Value == 905080000)
                        {
                            QueryExpression _queryforteams = new QueryExpression("team");
                            _queryforteams.ColumnSet = new ColumnSet(new string[] { "country", "businessunitid" });
                            EntityCollection _teams = client.RetrieveMultiple(_queryforteams);
                            foreach (var c_team in _teams.Entities)
                            {
                                if (c_team.Attributes["country"].ToString() == "India")
                                {
                                    QueryExpression _Query = new QueryExpression();
                                    _Query.EntityName = "systemuser";
                                    _Query.ColumnSet = new ColumnSet(true);
                                    _Query.ColumnSet.AddColumn("systemuserid");
                                    _Query.LinkEntities.Add(new LinkEntity
                                    {
                                        LinkFromEntityName = "systemuser",
                                        LinkToEntityName = "teammembership",
                                        LinkFromAttributeName = "systemuserid",
                                        LinkToAttributeName = "systemuserid",
                                        LinkCriteria =
                                                new FilterExpression
                                                {
                                                    Conditions ={
                            new ConditionExpression("teamid",ConditionOperator.Equal,c_team.Id)
                                                                }
                                                }
                                    });
                                    EntityCollection team_users = client.RetrieveMultiple(_Query);
                                    foreach (var tu in team_users.Entities)
                                    {

                                        QueryExpression qe = new QueryExpression("lead")
                                        {
                                            ColumnSet = new ColumnSet(new string[] { "leadid", "ownerid", "fullname", "emailaddress1" }),
                                            Criteria =
{
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
        //new ConditionExpression("leadid", ConditionOperator.Equal, new Guid("{8C9FE1B9-ED62-E711-A815-00155D02DE23}")),
        //new ConditionExpression("statuscode", ConditionOperator.Equal, 3),
        new ConditionExpression("ownerid", ConditionOperator.Equal, tu.Id),
    },
},
}
}
                                        };
                                        EntityCollection Assigend_records = client.RetrieveMultiple(qe);
                                        if (Assigend_records.Entities.Count <= 26)

                                        {
                                            AssignRequest assign = new AssignRequest
                                            {
                                                Assignee = new EntityReference("systemuser",
                                                          tu.Id),
                                                Target = new EntityReference("lead",
                                                          _leadID)
                                            };
                                            client.Execute(assign);
											}
											}
											}
											}
											}



Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images