/// <summary> /// Executes the plug-in. /// </summary> /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the /// <see cref="IPluginExecutionContext"/>, /// <see cref="IOrganizationService"/> /// and <see cref="ITracingService"/> /// </param> /// <remarks> /// For improved performance, Microsoft Dynamics CRM caches plug-in instances. /// The plug-in's Execute method should be written to be stateless as the constructor /// is not called for every invocation of the plug-in. Also, multiple system threads /// could execute the plug-in at the same time. All per invocation state information /// is stored in the context. This means that you should not use global variables in plug-ins. /// </remarks> protected void ExecutePrePFRRegistrationUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } ITracingService tracingService = localContext.TracingService; IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService orgService = localContext.OrganizationService; Entity targetEntity = context.InputParameters.ContainsKey(Resource.Target) ? context.InputParameters[Resource.Target] as Entity : null; Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null; //throw new InvalidPluginExecutionException("Target entity:" + targetEntity.LogicalName + "PreimageEntity is:"+ preImageEntity.LogicalName); if (targetEntity == null || preImageEntity == null) { return; } try { //targetEntity["crs_webformsteppageid"] = 0; //Initialize the preimageEntity webform step to 0 so that the record can be created, if not, the lugin will throw a given key dictionary error //Integer Field to determine what webform step the user is on //int pfrWebformStep = (int)preImageEntity["crs_webformsteppageid"]; string targetpfrWebformStep = (string)targetEntity["crs_webformstepid"]; //throw new InvalidPluginExecutionException("does it exists (preimage) " + preImageEntity.Contains("crs_webformsteppageid") + "-" + (preImageEntity["crs_webformsteppageid"] == null + "does it exists (preimage) " + targetEntity.Contains("crs_webformsteppageid") + "-" + (targetEntity["crs_webformsteppageid"] == null))); //throw new InvalidPluginExecutionException("does it exists (targetimage) " + targetEntity.Contains("crs_webformsteppageid") + "-" + (targetEntity["crs_webformsteppageid"] == null)); SubgridValidatorHelper subgridHelper = new SubgridValidatorHelper(); //throw new InvalidPluginExecutionException("Webform step:" + targetpfrWebformStep); if (targetpfrWebformStep != null && targetpfrWebformStep == "cff0a988-e567-e711-80f3-005056900bb7") { //throw new InvalidPluginExecutionException(" In webform 4.2 Logic:" + targetpfrWebformStep); //Boolean field For the PFR Percentage Owners (crs_pfrpercentageowner) subgrid //bool officersOwnTenPercentOrMore = (bool)preImageEntity["crs_pfrregownership"]; bool officersOwnTenPercentOrMore = (bool)targetEntity["crs_pfrregownership"]; //Boolean field For the PFR Percentage Owners other Businesses (crs_pfrpercentageownersotherbusiness) subgrid bool officersOtherbusiness = (bool)targetEntity["crs_crs_pfrregownershipotherbusinesses"]; //Boolean field for the PFR Capital Stock Owners (crs_pfrregcapitalstockowner) subgrid bool pfrRegCapitalStockOwner = (bool)targetEntity["crs_pfrregcapitalstockowner"]; //Boolean field for the PFR Contracted Charitable Organizations (crs_pfrcontractedcharitableorganization) subgrid bool pfrRegCapitalStockOwnerCharitableOrg = (bool)targetEntity["crs_pfrregcapitalstockownercharorg"]; //Boolean field for the PFR Charitable Organization Independent (crs_pfrindependentcharitableorg) subgrid bool registrantHaveCharitableOrgContractsIndependent = (bool)targetEntity["crs_pfrregindependentnjcharorgcontract"]; //Boolean field for the PFR Uses SubContractors(crs_pfrusessubcontractor) subgrid bool usesSubcontractor = (bool)targetEntity["crs_usesasubcontractor"]; //Boolean field for the PFR Campaign Lists (crs_pfrcampaignlist) subgrid bool conductedCharitableCampaigns = (bool)targetEntity["crs_conductedcampaigns"]; //Boolean field for the PFR Charitable Org Solicitations (crs_pfrcharitableorgsolicitation) subgrid bool retainedSolicitationActivities = (bool)targetEntity["crs_engagedorretainedsolicitationactivities"]; //Boolean field for the PFR Registrant Permits and License (crs_pfrregistrantpermitsandlicense) subgrid bool permitsAndLicenses = (bool)targetEntity["crs_pfrregistrantpermitsandlicenses"]; if (officersOwnTenPercentOrMore == true) { Boolean subgrid1 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrpercentageowner", "crs_pfrreg10percentormoreownerid", 5); if (!subgrid1)//if(subgrid1== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Do any of the registrant’s officers, directors, partners and shareholders own 10% or more?' You must enter at least 5 records."); } } if (officersOtherbusiness == true) { Boolean subgrid2 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrpercentageownersotherbusiness", "crs_pfrregpercentageownerotherbusinid", 5); if (!subgrid2)//if(subgrid2== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Do any of the registrant’s officers, directors, executive personnel, employees or owners of ten percent (10%) or more of its capital stock also own, control, manage or operate any other business besides the business of fundraising?' You must enter at least 5 records."); } } if (pfrRegCapitalStockOwner == true) { Boolean subgrid3 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrregcapitalstockowner", "crs_pfrcapitalstockownerid", 5); if (!subgrid3)//if(subgrid3== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Are any of the registrant’s members, officers, directors, executive personnel or employees the owners of ten percent (10%) or more of its capital stock?' You must enter at least 5 records."); } } if (pfrRegCapitalStockOwnerCharitableOrg == true) { Boolean subgrid4 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrcontractedcharitableorganization", "crs_pfrregcontractedcharitableorgid", 5); if (!subgrid4)//if(subgrid4== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Do any of the registrant’s members, officers, directors, executive personnel, employees or owners of ten percent (10%) or more of its capital stock also have any affiliation or association with any client (contracted charitable organization)?' You must enter at least 5 records."); } } if (registrantHaveCharitableOrgContractsIndependent == true) { Boolean subgrid5 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrindependentcharitableorg", "crs_pfrregcharitableorgindependentid", 5); if (!subgrid5)//if(subgrid5== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Does the registrant have any contracts with charitable organizations which currently retain the registrant to act as an independent paid fund raiser or fund-raising counsel in the State of New Jersey or partly in the State of New Jersey?' You must enter at least 5 records."); } } if (usesSubcontractor == true) { Boolean subgrid6 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrusessubcontractor", "crs_pfrregsubcontractorid", 5); if (!subgrid6)//if(subgrid6== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Does the registrant currently subcontract or assign its rights under contract to any independent paid fund raiser, fund-raising counsel or other entity, or accept responsibility as assigned subcontractor?' You must enter at least 5 records."); } } if (conductedCharitableCampaigns == true) { Boolean subgrid7 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrcampaignlist", "crs_pfrregcampaignlistid", 5); if (!subgrid7)//if(subgrid7== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Did the registrant conduct any charitable campaigns in whole or in part during its last fiscal year?' You must enter at least 5 records."); } } if (retainedSolicitationActivities == true) { Boolean subgrid8 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrcharitableorgsolicitation", "crs_pfrregcharitableorgsolicitationid", 5); if (!subgrid8)//if(subgrid8== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Have any charitable organizations, within the last five (5) years, engaged or retained the registrant’s services to plan or conduct solicitation activities in the State of New Jersey?' You must enter at least 5 records."); } } if (permitsAndLicenses == true) { Boolean subgrid8 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrregistrantpermitsandlicense", "crs_pfrregistrantpermitsid", 5); if (!subgrid8)//if(subgrid8== false) { throw new InvalidPluginExecutionException("You answered yes to the question:'Does the registrant have a license, registration or permit from any other state agency where the registrant's services can be engaged or retained as an independent paid fund raiser or fund-raising counsel by a charitable organization (whether or not the registrant actually conducts solicitations for the charity)?' You must enter at least 5 records."); } } } //throw new InvalidPluginExecutionException("Exited 4.2 Logic:" + targetpfrWebformStep); if (targetpfrWebformStep != null && targetpfrWebformStep == "407b06b1-e567-e711-80f3-005056900bb7") { //throw new InvalidPluginExecutionException(" In webform 4.3 Logic:" + targetpfrWebformStep); //Boolean field for the PFR Charitable Org Donated Tickets (crs_pfrcharitableorgdonatedticket) subgrid bool registrantRepresentedTicket = (bool)targetEntity["crs_registrantrepresentedticket"]; if (registrantRepresentedTicket == true) { Boolean subgrid9 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrcharitableorgdonatedticket", "crs_pfrregcharitableorgticketsdonatid", 5); if (!subgrid9)//if(subgrid9== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Did the registrant, during its solicitations in the last year, represent that tickets to an event would be donated by another for the benefit of a charitable organization?' You must enter at least 5 records."); } } } if (targetpfrWebformStep == null) { return; } this.PerformOperation(orgService, targetEntity, preImageEntity); // Clear off the acknowledgement related fields which are displayed on the declaration page. This is to ensure that the user explicitly checks them each time targetEntity["crs_p_decl_inforeviewed"] = false; targetEntity["crs_p_decl_supportingdocumentsuploaded"] = false; targetEntity["crs_p_decl_madeupdaterequestbyNPRP"] = false; } catch (FaultException <OrganizationServiceFault> e) { Logger.Log(string.Format(CultureInfo.InvariantCulture, "{0} {1}", "Exception: {0}", e.ToString()), null, tracingService); throw; } finally { Logger.Log(string.Format(CultureInfo.InvariantCulture, "{0} {1}", "Exiting {0}.Execute()", this.ChildClassName), null, tracingService); } }
/// <summary> /// Executes the plug-in. /// </summary> /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the /// <see cref="IPluginExecutionContext"/>, /// <see cref="IOrganizationService"/> /// and <see cref="ITracingService"/> /// </param> /// <remarks> /// For improved performance, Microsoft Dynamics CRM caches plug-in instances. /// The plug-in's Execute method should be written to be stateless as the constructor /// is not called for every invocation of the plug-in. Also, multiple system threads /// could execute the plug-in at the same time. All per invocation state information /// is stored in the context. This means that you should not use global variables in plug-ins. /// </remarks> protected void ExecutePreCharityRegistrationUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } ITracingService tracingService = localContext.TracingService; IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService orgService = localContext.OrganizationService; Entity targetEntity = context.InputParameters.ContainsKey(Resource.Target) ? context.InputParameters[Resource.Target] as Entity : null; Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null; if (targetEntity == null || preImageEntity == null) { return; } try { //<****************************************************Beginning of Donovan PFR Registration Subgrid Record Validation Plugin Code. Last Updated 7/28/2017*************************************************************************************************> /*<Code Summary> * This part of the plugin is to validate whether or not the child entities(subgrids) on certain webform steps have at least 5 records if the user answers 'Yes' on * Certain Boolean Fields */ //Field to capture the webform step id. This field is set via the client side JavaScript Code written at the webpage level string targetCharityRegWebformStep = (string)targetEntity["crs_webformstepid"]; SubgridValidatorHelper subgridHelper = new SubgridValidatorHelper(); if (targetCharityRegWebformStep != null && targetCharityRegWebformStep == "23f94f36-9d56-e711-80f3-005056900bb7") { bool commonQuestion14 = (bool)targetEntity["crs_cmnquestion14"]; if (commonQuestion14 == true) { Boolean cmnsubgrid1 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_pfrandcoventure", "crs_charityregistrationcoventureidid", 5); if (!cmnsubgrid1)//if(cmnsubgrid1== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Has the organization used a commercial co-venture?' You must enter at least 5 records."); } } } if (targetCharityRegWebformStep != null && targetCharityRegWebformStep == "b504c31b-9f56-e711-80f3-005056900bb7") { bool shortFormQuestion1 = (bool)targetEntity["crs_shrtquestion1"]; bool shortFormQuestion6 = (bool)targetEntity["crs_shrtquestion6"]; if (shortFormQuestion1 == true) { Boolean shortsubgrid1 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_statessolicitedin", "crs_charityregstatessolicitedid", 5); if (!shortsubgrid1)//if(shortsubgrid1== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Does the organization register or solicit in other states?' You must enter at least 5 records."); } } if (shortFormQuestion6 == true) { Boolean shortsubgrid2 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_highestpaidemployee", "crs_charityreghighestpaidemployeeid", 5); if (!shortsubgrid2)//if(shortsubgrid2== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Does the organization have five employees that are compensated the most?' You must enter at least 5 records."); } } } if (targetCharityRegWebformStep != null && targetCharityRegWebformStep == "39f09960-9f56-e711-80f3-005056900bb7") { bool longFormQuestion1 = (bool)targetEntity["crs_longquestion1"]; bool longFormQuestion2 = (bool)targetEntity["crs_longquestion2"]; bool longFormQuestion11 = (bool)targetEntity["crs_longquestion11"]; if (longFormQuestion1 == true) { Boolean longsubgrid1 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_statessolicitedin", "crs_charityregstatessolicitedid", 5); if (!longsubgrid1)//if(longsubgrid1== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Does the organization register or solicit in other states?' You must enter at least 5 records."); } } if (longFormQuestion2 == true) { Boolean longsubgrid2 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_charityaffiliate", "crs_charityregistrationaffiliateid", 5); if (!longsubgrid2)//if(longsubgrid2== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Does the organization have affiliates which share the contributions or other revenue it raised in New Jersey?' You must enter at least 5 records."); } } if (longFormQuestion11 == true) { Boolean longsubgrid11 = subgridHelper.SubgridRecordCountIsValid(orgService, targetEntity.Id, "crs_highestpaidemployee", "crs_charityreghighestpaidemployeeid", 5); if (!longsubgrid11)//if(longsubgrid11== false) { throw new InvalidPluginExecutionException("You answered yes to the question: 'Does the organization have five employees that are compensated the most?' You must enter at least 5 records."); } } } if (targetCharityRegWebformStep == null) { return; } //<****************************************************End of Donovan PFR Registration Subgrid Record Validation Plugin Code. Last Updated 7/28/2017*************************************************************************************************> /* As of 7/28/2017 Lenin be sure to do regression testing on the filtering attributes * The plugin was firing on all attributes on the update step before * Donovan changed this so that the filtering attributes are only: crs_p_decl_inforeviewed, crs_p_decl_supportingdocumentsuploaded, crs_p_decl_madeupdaterequestbyNPRP * */ PreCharityRegistrationUpdateHelper helper = new PreCharityRegistrationUpdateHelper(); helper.PerformOperation(orgService, targetEntity, preImageEntity); // Clear off the acknowledgement related fields which are displayed on the declaration page. This is to ensure that the user explicitly checks them each time targetEntity["crs_p_decl_inforeviewed"] = false; targetEntity["crs_p_decl_supportingdocumentsuploaded"] = false; targetEntity["crs_p_decl_madeupdaterequestbyNPRP"] = false; } catch (FaultException <OrganizationServiceFault> e) { Logger.Log(string.Format(CultureInfo.InvariantCulture, "{0} {1}", "Exception: {0}", e.ToString()), null, tracingService); throw; } finally { Logger.Log(string.Format(CultureInfo.InvariantCulture, "{0} {1}", "Exiting {0}.Execute()", this.ChildClassName), null, tracingService); } }