コード例 #1
0
        /// <summary>
        /// this function will check if email contains data for lead.Lead can be qualify only when email present.
        /// register - QualifyLead - Syncronous- sandbox - Post Operation - database
        /// </summary>
        /// <param name="serviceProvider"></param>
        public void Execute(IServiceProvider serviceProvider)
        {
            var pluginObject = PluginUtility.CRMService(serviceProvider);

            try
            {
                pluginObject.tracingService.Trace("Message: " + pluginObject.context.MessageName.ToUpper());
                if (pluginObject.context.MessageName.ToUpper() != LeadConstants.QUALIFYLEAD)
                {
                    return;
                }
                EntityReference leadid = (EntityReference)pluginObject.context.InputParameters[LeadConstants.LEADSCHEMAID];
                var             lead   = Helper.GetEntityById(pluginObject.service, LeadConstants.ENTITYSCHEMANAME, leadid.Id, new string[] { LeadConstants.FULLNAME, LeadConstants.EMAIL });
                if (lead != null)
                {
                    pluginObject.tracingService.Trace("Email : " + lead.GetAttributeValue <string>(LeadConstants.EMAIL));
                    if (string.IsNullOrEmpty(lead.GetAttributeValue <string>(LeadConstants.EMAIL)))
                    {
                        throw new InvalidPluginExecutionException("Lead cannot be qualified without email.");
                    }
                }
            }
            catch (InvalidPluginExecutionException ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        /// <summary>
        /// plugin registered in pre-validation stage(10). Syncronous - sandbox - database
        /// this function will check if contacts status is approved. If status is approved then associate the records with cropping else throw error and send email to contact
        /// </summary>
        /// <param name="serviceProvider"></param>
        public void Execute(IServiceProvider serviceProvider)
        {
            var pluginObject = PluginUtility.CRMService(serviceProvider);

            try
            {
                EntityReference           targetEntity     = null;
                string                    relationshipName = string.Empty;
                EntityReferenceCollection relatedEntities  = null;
                EntityReference           relatedEntity    = null;
                if (pluginObject.context.MessageName.ToUpper() == GlobalConstants.ASSOCIATE)
                {
                    if (pluginObject.context.InputParameters.Contains("Relationship"))
                    {
                        relationshipName = pluginObject.context.InputParameters["Relationship"].ToString();
                    }
                    if (relationshipName != GlobalConstants.RELATIONSHIP_CONTACT_CROPPING)
                    {
                        return;
                    }

                    // Get Entity 1 reference from "Target" Key from context
                    if (pluginObject.context.InputParameters.Contains(GlobalConstants.TARGET) && pluginObject.context.InputParameters[GlobalConstants.TARGET] is EntityReference)
                    {
                        targetEntity = (EntityReference)pluginObject.context.InputParameters[GlobalConstants.TARGET];
                        pluginObject.tracingService.Trace("Target Entity : " + targetEntity.LogicalName);
                    }
                    // Get Entity 2 reference from  RelatedEntities Key
                    if (pluginObject.context.InputParameters.Contains(GlobalConstants.RELATEDENTITIES) && pluginObject.context.InputParameters[GlobalConstants.RELATEDENTITIES] is EntityReferenceCollection)
                    {
                        relatedEntities = pluginObject.context.InputParameters[GlobalConstants.RELATEDENTITIES] as EntityReferenceCollection;
                        relatedEntity   = relatedEntities[0];
                        pluginObject.tracingService.Trace("Related Entity : " + relatedEntity.LogicalName);
                        Entity contact = pluginObject.service.Retrieve(relatedEntity.LogicalName, relatedEntity.Id, new ColumnSet(GlobalConstants.STATUSCODE, GlobalConstants.EMAIL));
                        if (contact.GetAttributeValue <OptionSetValue>(GlobalConstants.STATUSCODE).Value != GlobalConstants.APPROVED)
                        {
                            //send email to contact
                            Helper.SendEmail(contact.GetAttributeValue <string>(GlobalConstants.EMAIL));
                            //throw exception
                            throw new InvalidPluginExecutionException("Contact status should be approved");
                        }
                    }
                }
            }
            catch (InvalidPluginExecutionException ex)
            {
                throw ex;
            }
        }