Setting screen properties within a multiblock ASP page using the COM API

Less than one minute read time.

This COM API trick for ASP based Application Extensions shows how you can create a screen with 2 (or more) blocks where one of the blocks remains in view mode regardless of the value of CRM.Mode.

It is a very simple approach and all you have to do is get hold of the block that you wish to be read only and then roll through its fields setting them to be readonly. The tip relies on the screen or entrygroup block being an enumerable object.


var OppoRecordId = CRM.GetContextInfo("opportunity","oppo_opportunityid");

var OppoRecord = CRM.FindRecord("opportunity","oppo_opportunityid="+intRecordId);
var OppoWebPickerBlock = CRM.GetBlock("OpportunityWebPicker");
var OppoDetailBoxBlock = CRM.GetBlock("OpportunityDetailBox");

var myBlockContainer = CRM.GetBlock("Container");
with (myBlockContainer)
{
AddBlock(OppoWebPickerBlock);
AddBlock(OppoDetailBoxBlock);
}

OppoWebPickerBlock.ArgObj = OppoRecord;
OppoDetailBoxBlock.ArgObj = OppoRecord;

//Set EntryBlock properties for an EntryGroup Block using an Enumerator
var myE = new Enumerator(myBlock);
while (!myE.atEnd())
{
myEntryBlock = myE.item();
myEntryBlock.ReadOnly = false;
myEntryBlock.Required = false;

myE.moveNext();
}

CRM.AddContent(myBlockContainer.Execute());
Response.Write(CRM.GetPage());