protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { var account = XrmContext.CreateQuery("account").FirstOrDefault(c => c.GetAttributeValue <Guid>("accountid") == e.EntityId); if (account == null) { throw new Exception(string.Format("An account with the account ID equal to {0} couldn’t be found.", e.EntityId)); } var parentCustomerAccount = Contact.GetAttributeValue <EntityReference>("parentcustomerid") == null ? null : XrmContext.CreateQuery("account").FirstOrDefault(a => a.GetAttributeValue <Guid>("accountid") == Contact.GetAttributeValue <EntityReference>("parentcustomerid").Id); if (parentCustomerAccount == null) { throw new Exception("Parent Customer Account could not be found associated to the current user's contact."); } account.SetAttributeValue("msa_managingpartnerid", parentCustomerAccount.ToEntityReference()); var accountId = account.GetAttributeValue <Guid>("accountid"); XrmContext.UpdateObject(account); XrmContext.SaveChanges(); var url = GetUrlForRequiredSiteMarker("Create Customer Contact"); url.QueryString.Set("AccountId", accountId.ToString()); url.QueryString.Set("SetAsPrimary", "true"); url.QueryString.Set(FromCreateOpportunity ? "FromCreateOpportunity" : "ReturnToAccount", "true"); Response.Redirect(url.PathWithQueryString); }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { if (e.EntityId == null | e.EntityId == Guid.Empty) { throw new ApplicationException("The ID of the created record wasn't provided. This is usually a result of a plug-in failure. To troubleshoot, please check the ASP.NET trace or review the failed system jobs."); } var newId = e.EntityId ?? Guid.Empty; var attachment = (FileUpload)CreateCaseForm.FindControl("FormView").FindControl("Attachment"); var caseDataAdapter = new CaseDataAdapter(new EntityReference("incident", newId), new PortalContextDataAdapterDependencies(Portal, PortalName, Request.RequestContext)); if (attachment != null && attachment.HasFile) { caseDataAdapter.AddNote(string.Empty, attachment.PostedFile.FileName, attachment.PostedFile.ContentType, attachment.FileBytes); } // redirect to the case var page = ServiceContext.GetPageBySiteMarkerName(Website, "Case"); if (page == null) { throw new ApplicationException("Required Site Marker named 'Case' does not exist."); } var url = new UrlBuilder(ServiceContext.GetUrl(page)); url.QueryString.Set("caseid", newId.ToString()); Response.Redirect(url.PathWithQueryString); }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { RegistrationMessage.CssClass = "RegistrationSuccess"; RegistrationMessage.Text = ServiceContext.GetSnippetValueByName(Website, "ProductRegistration/RegistrationSuccess"); RegForm.Visible = false; }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { var account = XrmContext.CreateQuery("account").FirstOrDefault(a => a.GetAttributeValue <Guid>("accountid") == (Contact.GetAttributeValue <EntityReference>("parentcustomerid") == null ? Guid.Empty : Contact.GetAttributeValue <EntityReference>("parentcustomerid").Id)); var contact = XrmContext.CreateQuery("contact").FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == e.EntityId); if (account == null || contact == null) { throw new Exception("Unable to retrieve account or contact for the logged in user."); } contact.SetAttributeValue("parentcustomerid", account.ToEntityReference()); //XrmContext.UpdateObject(account); if (Invite) { InviteContact(contact); } XrmContext.UpdateObject(contact); XrmContext.SaveChanges(); var url = GetUrlForRequiredSiteMarker("Manage Partner Account"); Response.Redirect(url.PathWithQueryString); }
private void FormViewInserted(object sender, CrmEntityFormViewInsertedEventArgs args) { if (FileUpload == null || !FileUpload.HasFiles || !args.EntityId.HasValue) { return; } var regarding = new EntityReference(Metadata.TargetEntityName, args.EntityId.Value); var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(); var dataAdapter = new SharePointDataAdapter(dataAdapterDependencies); dataAdapter.AddFiles(regarding, FileUpload.PostedFiles.Select(file => new HttpPostedFileWrapper(file) as HttpPostedFileBase).ToList()); }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { ContactForm.Visible = false; ConfirmationMessage.Visible = true; }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { var contact = XrmContext.CreateQuery("contact").FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == e.EntityId); if (contact == null) { throw new Exception(string.Format("A contact couldn't be found with a contact ID equal to {0}.", e.EntityId)); } var parentCustomerAccount = Contact.GetAttributeValue <EntityReference>("parentcustomerid") == null ? null : ServiceContext.CreateQuery("account").FirstOrDefault(a => a.GetAttributeValue <Guid>("accountid") == Contact.GetAttributeValue <EntityReference>("parentcustomerid").Id); if (parentCustomerAccount == null) { throw new Exception("Parent Customer Account could not be found associated to the current user's contact."); } Guid accountId = (Guid.TryParse(CompanyNameList.SelectedValue, out accountId)) ? accountId : Guid.Empty; var account = XrmContext.CreateQuery("account").FirstOrDefault(a => a.GetAttributeValue <Guid>("accountid") == accountId); var opportunity = OriginatingOpportunity == null ? null : XrmContext.CreateQuery("opportunity").FirstOrDefault(o => o.GetAttributeValue <Guid>("opportunityid") == OriginatingOpportunity.Id); if (opportunity != null) { var contactCrossover = opportunity.GetRelatedEntities(XrmContext, new Relationship("adx_opportunity_contact")).FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == contact.GetAttributeValue <Guid>("contactid")); var oppnote = new Entity("adx_opportunitynote"); if (contactCrossover == null) { XrmContext.AddLink(opportunity, new Relationship("adx_opportunity_contact"), contact); oppnote.SetAttributeValue("adx_name", "Contact Added: " + contact.GetAttributeValue <string>("fullname")); oppnote.SetAttributeValue("adx_date", DateTime.UtcNow); oppnote.SetAttributeValue("adx_description", "Contact Added: " + contact.GetAttributeValue <string>("fullname")); oppnote.SetAttributeValue("adx_opportunityid", opportunity.ToEntityReference()); var assignedToContact = opportunity.GetRelatedEntity(XrmContext, new Relationship("msa_contact_opportunity")); oppnote.SetAttributeValue("adx_assignedto", assignedToContact != null ? assignedToContact.GetAttributeValue <string>("fullname") : string.Empty); XrmContext.AddObject(oppnote); XrmContext.UpdateObject(opportunity); } } contact.SetAttributeValue("msa_managingpartnerid", parentCustomerAccount.ToEntityReference()); if (account != null) { contact.SetAttributeValue("parentcustomerid", account.ToEntityReference()); XrmContext.UpdateObject(account); } XrmContext.UpdateObject(contact); if (SetAsPrimary) { if (account == null) { throw new Exception(string.Format("An account with the account ID equal to {0} couldn’t be found.", accountId)); } account.SetAttributeValue("primarycontactid", contact.ToEntityReference()); XrmContext.UpdateObject(account); } XrmContext.SaveChanges(); if (opportunity != null) { var url = GetUrlForRequiredSiteMarker("Opportunity Details"); url.QueryString.Set("OpportunityID", opportunity.GetAttributeValue <Guid>("opportunityid").ToString()); Response.Redirect(url.PathWithQueryString); } else if (ReturnToAccount) { if (account == null) { throw new Exception(string.Format("An account with the account ID equal to {0} couldn’t be found.", accountId)); } var url = GetUrlForRequiredSiteMarker("Edit Customer Account"); url.QueryString.Set("AccountID", account.Id.ToString()); Response.Redirect(url.PathWithQueryString); } else if (FromCreateOpportunity) { if (account == null) { throw new Exception(string.Format("An account with the account ID equal to {0} couldn’t be found.", accountId)); } var url = GetUrlForRequiredSiteMarker("Create Opportunity"); url.QueryString.Set("AccountId", account.Id.ToString()); Response.Redirect(url.PathWithQueryString); } else { var url = GetUrlForRequiredSiteMarker("Manage Customer Contacts"); Response.Redirect(url.PathWithQueryString); } }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { ThankYouPanel.Visible = true; FeedbackFormPanel.Visible = false; }
protected void NewComment_OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { Response.Redirect(Request.Url.PathAndQuery); }
protected void OnItemInserted(object sender, CrmEntityFormViewInsertedEventArgs e) { var opportunity = XrmContext.CreateQuery("opportunity").First(o => o.GetAttributeValue <Guid>("opportunityid") == e.EntityId); var opportunityProductsFromLead = opportunity.GetAttributeValue <string>("adx_opportunityproductsfromlead"); var productsList = new List <Entity>(); if (!string.IsNullOrEmpty(opportunityProductsFromLead)) { var products = XrmContext.CreateQuery("product"); var words = opportunityProductsFromLead.Split(','); foreach (var word in words) { foreach (var product in products) { if (product.GetAttributeValue <string>("name").Trim().ToUpper() == word.Trim().ToUpper()) { productsList.Add(product); } } } } foreach (var leadProduct in productsList) { if (!XrmContext.IsAttached(leadProduct)) { XrmContext.Attach(leadProduct); } XrmContext.AddLink(opportunity, new Relationship("adx_opportunity_product"), leadProduct); } opportunity.SetAttributeValue("adx_referencecode", GetOpportunityReferenceCode()); var salesStage = opportunity.GetAttributeValue <OptionSetValue>("salesstagecode") == null ? 0 : opportunity.GetAttributeValue <OptionSetValue>("salesstagecode").Value; var response = (RetrieveAttributeResponse)ServiceContext.Execute(new RetrieveAttributeRequest { EntityLogicalName = "opportunity", LogicalName = "salesstagecode" }); var picklist = response.AttributeMetadata as PicklistAttributeMetadata; if (picklist == null) { return; } foreach (var option in picklist.OptionSet.Options) { if (option != null && option.Value != null && option.Value.Value == salesStage) { opportunity.SetAttributeValue("stepname", option.Label.GetLocalizedLabelString()); } } var leadType = XrmContext.CreateQuery("adx_leadtype").FirstOrDefault(lt => lt.GetAttributeValue <string>("adx_name") == "Partner Created"); if (leadType != null) { opportunity.SetAttributeValue("adx_leadtypeid", leadType.ToEntityReference()); } XrmContext.UpdateObject(opportunity); XrmContext.SaveChanges(); var url = GetUrlForRequiredSiteMarker("Accepted Opportunities"); Response.Redirect(url); }