protected void OnItemInserting(object sender, CrmEntityFormViewInsertingEventArgs e) { var product = XrmContext.ProductSet.First(p => p.Name == Product.SelectedValue); var serialNumbers = XrmContext.MSA_productregistrationSet .Where(pr => pr.MSA_SerialNumber == e.Values["msa_serialnumber"].ToString()) .ToList(); if (serialNumbers.Any()) { RegistrationMessage.CssClass = "RegistrationFailure"; RegistrationMessage.Text = ServiceContext.GetSnippetValueByName(Website, "ProductRegistration/RegistrationFailure"); e.Cancel = true; RegForm.Visible = false; return; } e.Values["msa_customercontactid"] = Contact.ToEntityReference(); var account = Contact.contact_customer_accounts; if (account != null) { e.Values["msa_customeraccountid"] = account.ToEntityReference(); } e.Values["msa_registeredproductid"] = product.ToEntityReference(); e.Values["adx_createdbyusername"] = Contact.FullName; e.Values["adx_createdbyipaddress"] = Request.UserHostAddress; }
protected void OnItemInserting(object sender, CrmEntityFormViewInsertingEventArgs e) { var schedule = XrmContext.CreateQuery("adx_eventschedule").FirstOrDefault(sn => sn.GetAttributeValue <Guid>("adx_eventscheduleid") == SessionEventScheduleID); e.Values["adx_name"] = GetEventNameFromSchedule(XrmContext, schedule) + " session feedback from " + Contact.GetAttributeValue <string>("fullname"); e.Values["adx_attendeeid"] = Contact.ToEntityReference(); if (schedule != null) { e.Values["adx_eventscheduleid"] = schedule.ToEntityReference(); } }
protected void OnItemInserting(object sender, CrmEntityFormViewInsertingEventArgs e) { var currentContact = XrmContext.MergeClone(Contact); if (currentContact == null) { return; } var contactParentCustomerAccount = currentContact.GetRelatedEntity(XrmContext, new Relationship("contact_customer_accounts")); if (contactParentCustomerAccount != null) { e.Values["msa_partnerid"] = contactParentCustomerAccount.ToEntityReference(); } e.Values["msa_partneroppid"] = currentContact.ToEntityReference(); e.Values["adx_createdbyusername"] = Contact.GetAttributeValue <string>("fullname"); // e.Values["adx_createdbyipaddress"] = Request.UserHostAddress ?? ""; e.Values["adx_partnercreated"] = true; // If no estimated revenue was submitted, leave as system-calculated. e.Values["isrevenuesystemcalculated"] = (!e.Values.ContainsKey("estimatedvalue")) || (e.Values["estimatedvalue"] == null); Guid accountId; if ((Account_dropdown.SelectedItem == null || Account_dropdown.SelectedIndex == 0) || !Guid.TryParse(Account_dropdown.SelectedItem.Value, out accountId)) { return; } var account = XrmContext.CreateQuery("account").FirstOrDefault(a => a.GetAttributeValue <Guid>("accountid") == accountId); if (account != null) { e.Values["customerid"] = account.ToEntityReference(); } }
protected void NewComment_OnItemInserting(object sender, CrmEntityFormViewInsertingEventArgs e) { var commentAdapterFactory = new CommentDataAdapterFactory(Entity.ToEntityReference()); var dataAdapter = commentAdapterFactory.GetAdapter(Portal, Request.RequestContext); if (dataAdapter == null) { Visible = false; return; } var content = e.Values[dataAdapter.GetCommentContentAttributeName()]; var sanitizedContent = new WhiteListHtmlSanitizer(true).Sanitize(content == null ? string.Empty : content.ToString()); var attributes = dataAdapter.GetCommentAttributes(sanitizedContent, CommentAuthorName.Text, CommentAuthorEmail.Text, CommentAuthorUrl.Text, Context); foreach (var attribute in attributes) { e.Values[attribute.Key] = attribute.Value; } }
protected void OnItemInserting(object sender, CrmEntityFormViewInsertingEventArgs e) { var customerDropdown = (DropDownList)CreateCaseForm.FindControl("FormView").FindControl("CustomerDropdown"); if (customerDropdown == null) { e.Values["customerid"] = Contact.ToEntityReference(); } else { Guid customerId; if (Guid.TryParse(customerDropdown.SelectedValue, out customerId)) { var customerLogicalName = customerId == Contact.Id ? "contact" : "account"; var customer = new EntityReference(customerLogicalName, customerId); e.Values["customerid"] = customer; } } if (!e.Values.ContainsKey("customerid")) { e.Values["customerid"] = Contact.ToEntityReference(); } if (!e.Values.ContainsKey("responsiblecontactid")) { e.Values["responsiblecontactid"] = Contact.ToEntityReference(); } e.Values["adx_createdbyusername"] = Contact.GetAttributeValue <string>("fullname"); // e.Values["adx_createdbyipaddress"] = Request.UserHostAddress; }
protected void OnItemInserting(object sender, CrmEntityFormViewInsertingEventArgs e) { }