Creating Complex Screens using the COM based ASP API

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Creating Complex Screens using the COM based ASP API

  • Comments 4
  • Likes
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.

Complex Screen Example

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.
Comments
  • Hi Jeff,

    I've used the above technique to add the person details the top of a summary screen for a custom entity (License).

    However, when I use the ArgObj property instead of passing in the record in the execute statement, the workflow for the license entity does not appear.

    Is there any way around this?

  • myBlock.WorkflowTable = "MyTable";

    myBlock.ShowWorkflowButtons = true;

    This code works when entrygroup block uses record object as execute method parameter.  But you could try passing the record into the execute method of the container.

  • Jeff...

    I have a complex screen that displays blocks from different tables (or views).  One of the blocks on the screen displays information from a view.  In some instances, there will not be a record associated with the company in context.  This works ok when the page is in view mode.  However, when the change button is hit, the system spins until it times out.  Over in VS debugging pops up and returns a message that basically says....there is no current record.  I am thinking that I need to either do a while statement or an if else statement to handle this.  I see a while statement in this example...but it appears that is making the companyboxlongBlock read only.  Are you aware of an example on the community that would assist me with what I need.  I have been looking on the community for something.  But I must not have the "magic search words" I need to find it.  

    Any assistance you can provide would be greatly appreciated.  Thank you!

  • 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);

    }