In an earlier article I showed how you could create a complex screen that allowed the editing multiple records in ASP. The actual example was the editing of a Company, Person and Address record all together.
You can find this discussed in the article "Example of a Complex Screen editing multiple records in ASP".
But how do you create a record of two or more different entities at once? Can we build our own version of the Company Entry screen?
The answer is yes we most certainly can! The code below is a partial rebuild only, as it doesn't cover the creation of the email and phone records. Be careful with those as actuall denormalisation back into the company and person records is required.
<%
if(CRM.Mode==View)
{
CRM.Mode=Edit;
}
var recCompany = CRM.CreateRecord("company");
var recAddress = CRM.CreateRecord("address");
var recPerson = CRM.CreateRecord("person");
var companyBlock = CRM.GetBlock("companyboxlong");
companyBlock.ArgObj = recCompany;
companyBlock.Title = CRM.GetTrans("tabnames","company");
var addressBlock = CRM.GetBlock("addressboxshort");
addressBlock.ArgObj=recAddress;
addressBlock.Title = CRM.GetTrans("tabnames","address");
var personBlock = CRM.GetBlock("personboxshort");
personBlock.ArgObj=recPerson;
personBlock.Title = CRM.GetTrans("tabnames","person");
var myBlockContainer = CRM.GetBlock("Container");
with (myBlockContainer)
{
AddBlock(companyBlock);
AddBlock(addressBlock);
AddBlock(personBlock);
}
CRM.AddContent(myBlockContainer.Execute());
if(CRM.Mode==Save)
{
recCompany.comp_primaryaddressid = recAddress.addr_addressid;
recCompany.comp_primarypersonid = recPerson.pers_personid;
recCompany.SaveChanges();
var recPersonLink = CRM.CreateRecord("person_link");
recPersonLink.peli_personid = recPerson.pers_personid;
recPersonLink.peli_companyid = recCompany.comp_companyid;
recPersonLink.SaveChanges();
var recAddressLink = CRM.CreateRecord("address_link");
recAddressLink.adli_addressid = recAddress.addr_addressid;
recAddressLink.adli_companyid = recCompany.comp_companyid;
recAddressLink.adli_personid = recPerson.pers_personid;
recAddressLink.SaveChanges();
Response.Redirect(CRM.Url("200")+" &key0=1 &key1="+recCompany.comp_companyid);
}
Response.Write(CRM.GetPage("new"));
%>
An article that discusses the creation of default Address and Persons for a Company is How do default addresses and persons get created for a Company?
An article that discusses the phone and email records is Email and Phone Numbers in CRM.