locked
Plugins: Passing count value RRS feed

  • Question

  • Hi ,
    i am trying to find the number of phonecall activity for a particular lead. I got the count value in int, but am getting an errror -"Value of type 'Int32' is not supported.\r\nParameter name: value" when i try to asign the value to a field in lead like this

    lead.Properties[

    "numberofemployees"] = num;//num is the count value

    am i doing anythng wrong???


    Thanks, Aarch
    • Changed type Aarch Wednesday, July 8, 2009 9:24 AM
    Wednesday, July 8, 2009 9:24 AM

Answers

  • Hi, Aarch.

    Try following:

    lead.Properties["numberofemployees" ] = new CrmNumber(num);


    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by Aarch Wednesday, July 8, 2009 9:58 AM
    Wednesday, July 8, 2009 9:47 AM
    Moderator
  • sure :-)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Query;
    
    namespace participantplugin
    {
        public class plugin : IPlugin
        {
            public void Execute(IPluginExecutionContext context)
            {
    
                Guid preLeadId = GetRegardingLeadId(context.PreEntityImages, "PhoneCall");
                Guid postLeadId = GetRegardingLeadId(context.PostEntityImages, "PhoneCall");
                ICrmService crmService = context.CreateCrmService(true);
                UpdateNextCallDueDate(crmService, preLeadId);
                if (preLeadId != postLeadId)
                {
                    UpdateNextCallDueDate(crmService, postLeadId);
                }
    
            }
            private Guid GetRegardingLeadId(PropertyBag images, string entityAlias)
            {
                Guid regardingLeadId = Guid.Empty;
                if (images.Contains(entityAlias))
                {
                    DynamicEntity entity = (DynamicEntity)images[entityAlias];
                    if (entity.Properties.Contains("regardingobjectid"))
                    {
                        Lookup regardingObjectId = (Lookup)entity["regardingobjectid"];
                        if (regardingObjectId.type == "lead")
                        {
                            regardingLeadId = regardingObjectId.Value;
                        }
                    }
                }
                return regardingLeadId;
            }
    
            private void UpdateNextCallDueDate(ICrmService crmService, Guid leadId)
            {
                if (leadId != Guid.Empty)
                {
                        DynamicEntity lead = new DynamicEntity("lead");
                    lead["leadid"] = new Key(leadId);
                    int num=GetNextScheduledPhoneCallForLead(crmService,leadId);
                                  lead.Properties["total"] = new CrmNumber(num);
    
                             crmService.Update(lead);
                }
            }
    
    
    
            private int GetNextScheduledPhoneCallForLead(ICrmService crmService, Guid leadId)
            {
                
    // give your queryexps
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = query;
                request.ReturnDynamicEntities = true;
                RetrieveMultipleResponse response;
                response = (RetrieveMultipleResponse)crmService.Execute(request);
               
                            int num = response.BusinessEntityCollection.BusinessEntities.Count;
                return num;
            }
    
        }
    }
    

    Thanks, Aarch
    • Proposed as answer by Nishant RanaMVP Wednesday, July 8, 2009 12:07 PM
    • Marked as answer by Aarch Thursday, July 16, 2009 5:58 AM
    Wednesday, July 8, 2009 11:45 AM

All replies

  • Hi,

    you have to use an instance of CrmNumber for the assignment.
    Wednesday, July 8, 2009 9:30 AM
  • i tried that ..but am getting error while built "Error 1 Cannot implicitly convert type 'Microsoft.Crm.Sdk.CrmNumber' to 'int' 
    Thanks, Aarch
    Wednesday, July 8, 2009 9:40 AM
  • Hi, Aarch.

    Try following:

    lead.Properties["numberofemployees" ] = new CrmNumber(num);


    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by Aarch Wednesday, July 8, 2009 9:58 AM
    Wednesday, July 8, 2009 9:47 AM
    Moderator
  • superb!! thanks a33ik :-)
    Thanks, Aarch
    Wednesday, July 8, 2009 9:58 AM
  • Hi Arch,

    Can you share your code with me,  it will be highly appreciated because even I'm also looking for a similar solution where I can track the no of counts.

    Thanx
    Prince
    Wednesday, July 8, 2009 11:25 AM
  • sure :-)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Query;
    
    namespace participantplugin
    {
        public class plugin : IPlugin
        {
            public void Execute(IPluginExecutionContext context)
            {
    
                Guid preLeadId = GetRegardingLeadId(context.PreEntityImages, "PhoneCall");
                Guid postLeadId = GetRegardingLeadId(context.PostEntityImages, "PhoneCall");
                ICrmService crmService = context.CreateCrmService(true);
                UpdateNextCallDueDate(crmService, preLeadId);
                if (preLeadId != postLeadId)
                {
                    UpdateNextCallDueDate(crmService, postLeadId);
                }
    
            }
            private Guid GetRegardingLeadId(PropertyBag images, string entityAlias)
            {
                Guid regardingLeadId = Guid.Empty;
                if (images.Contains(entityAlias))
                {
                    DynamicEntity entity = (DynamicEntity)images[entityAlias];
                    if (entity.Properties.Contains("regardingobjectid"))
                    {
                        Lookup regardingObjectId = (Lookup)entity["regardingobjectid"];
                        if (regardingObjectId.type == "lead")
                        {
                            regardingLeadId = regardingObjectId.Value;
                        }
                    }
                }
                return regardingLeadId;
            }
    
            private void UpdateNextCallDueDate(ICrmService crmService, Guid leadId)
            {
                if (leadId != Guid.Empty)
                {
                        DynamicEntity lead = new DynamicEntity("lead");
                    lead["leadid"] = new Key(leadId);
                    int num=GetNextScheduledPhoneCallForLead(crmService,leadId);
                                  lead.Properties["total"] = new CrmNumber(num);
    
                             crmService.Update(lead);
                }
            }
    
    
    
            private int GetNextScheduledPhoneCallForLead(ICrmService crmService, Guid leadId)
            {
                
    // give your queryexps
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = query;
                request.ReturnDynamicEntities = true;
                RetrieveMultipleResponse response;
                response = (RetrieveMultipleResponse)crmService.Execute(request);
               
                            int num = response.BusinessEntityCollection.BusinessEntities.Count;
                return num;
            }
    
        }
    }
    

    Thanks, Aarch
    • Proposed as answer by Nishant RanaMVP Wednesday, July 8, 2009 12:07 PM
    • Marked as answer by Aarch Thursday, July 16, 2009 5:58 AM
    Wednesday, July 8, 2009 11:45 AM