Creating Complex Screens using the COM based ASP API

1 minute read time.
I have blogged previously on creating multi-block screens based on a single record. A prime example of that would be when you need to design a page for a new entity that includes 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 screenshot, the user is able to alter both the Company and Opportunity records together.

Complex Screen Example

Below is the code that demonstrates how to construct this page. It allows the editing of two records from separate tables simultaneously. This code was called from a workflow global rule.
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));
}

The code above shows that we can handle records from multiple tables easily within the same page. Note in 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.
Parents
  • Michele

    I line of code like

    var companyRecord = CRM.FindRecord("company","comp_companyid="+intCompId);

    Assumes that a record is returned.

    We can check whether that is the case using the eof property.

    We can then guard adding the Block to the screen so that it is only added when there is a record to edit.

    with (myBlockContainer)

    {

    if (!companyRecord.eof)

    {

    AddBlock(companyboxlongBlock);

    }

    AddBlock(opportunitydetailboxBlock);

    }

Comment
  • Michele

    I line of code like

    var companyRecord = CRM.FindRecord("company","comp_companyid="+intCompId);

    Assumes that a record is returned.

    We can check whether that is the case using the eof property.

    We can then guard adding the Block to the screen so that it is only added when there is a record to edit.

    with (myBlockContainer)

    {

    if (!companyRecord.eof)

    {

    AddBlock(companyboxlongBlock);

    }

    AddBlock(opportunitydetailboxBlock);

    }

Children
No Data