I have
blogged previously on creating Multi block screens based on a single record. A prime example of that would be where you need to design a page for a new entity that include both a detailbox and a webpicker.
I would now like to consider a Complex screen where the ASP page offers the user the ability to edit two records at the same time. For example in the below screen shot the user is able to alter both the Company and Opportunity records together.
Below is the code that demonstates how to construct this page. It allows the editing of two records from seperate tables simultaneously. This code was called from a workflow global rule.
[code language="javascript"]if(CRM.Mode==View)
{
CRM.Mode = Edit;
}
var intOppoId = CRM.GetContextInfo("opportunity","oppo_opportunityid");
var intCompId = CRM.GetContextInfo("company","comp_companyid");
var companyboxlongBlock = CRM.GetBlock("companyboxlong");
companyboxlongBlock.Title = CRM.GetTrans("tabnames","company");
var opportunitydetailboxBlock = CRM.GetBlock("opportunitydetailbox");
opportunitydetailboxBlock.Title = CRM.GetTrans("tabnames","opportunity");
var opportunityRecord = CRM.FindRecord("opportunity","oppo_opportunityid="+intOppoId);
var companyRecord = CRM.FindRecord("company","comp_companyid="+intCompId);
if (!CRM.Button("test","test","test","COMPANY","Edit"))
{
var myE = new Enumerator(companyboxlongBlock);
while (!myE.atEnd())
{
myEntryBlock = myE.item();
myEntryBlock.ReadOnly = true;
myE.moveNext();
}
}
var myBlockContainer = CRM.GetBlock("Container");
with (myBlockContainer) { AddBlock(companyboxlongBlock);
AddBlock(opportunitydetailboxBlock);
}
companyboxlongBlock.ArgObj = companyRecord;
opportunitydetailboxBlock.ArgObj = opportunityRecord;
CRM.AddContent(myBlockContainer.Execute());
Response.Write(CRM.GetPage());
if(CRM.Mode==Save)
{
Response.Redirect(CRM.URL(260));
}
[/code]
The code above shows that we can handle records from multiple tables easily within the same page. Note the
italics that the ArgObj property is used to set the record in the screen rather than passing it within the Execute() method of the screen.
Please note this demonstrates the use of a security check that will change the edit rights for all fields on the block depending on whether the user has rights on the table.
I have written more about Security in Webpages
here and specifically about the technique for using an enumerator to set the properties of a block
here.