Basic Code Structure of an Edit Page

1 minute read time.
We should now consider the creation of an edit screen for a Record using an ASP page.

The structure is simpler.


var myBlock = eWare.GetBlock('OpportunityDetailBox'); 
var myRecordId = eWare.GetContextInfo('Opportunity','oppo_opportunityid'); 
//var myRecordId = Request.QueryString('oppo_opportunityid'); 
var myRecord = eWare.FindRecord('Opportunity','oppo_opportunityid='+myRecordId); 
eWare.AddContent(myBlock.Execute(myRecord)); 
Response.Write(eWare.GetPage());


The idea to always bear in mind is context. If you are dealing with a standard system entity (e.g. Company, Person, Opportunity etc) then you will be able to use the eWare.GetContextInfo() method to look for the primary key value for the record in context. From this you can then retrieve the record to be edited.

If you are working with a custom entity, perhaps one created using the Advanced Customization Wizard then you will need to get hold of the context information in another way as custom entities can't be accessed using the eWare.GetContextInfo() method.

The context information is held in the Key values of the hyperlink's query string.

The below code shows how to get hold of the correct key value that is contained in the querystring.


var strKeyID= "oppo_opportunityid"; 
var Id = new String(Request.Querystring(strKeyID)); 
var intRecordId = 0; 
if (Id.indexOf(",") > 0) 
{ 
var Idarr = Id.split(","); 
intRecordId = Idarr[0]; 
} 
else if (Id != "") 
{ 
intRecordId = Id; 
}


N.B. In ASP pages that are built using the Advanced Customization Wizard the querystring value that holds the context id value of the custom entity in context is "key58".
  • Michele

    The 'Arg' is a whereclause that only makes sense when restricting a list.

    The record is the 'AddressRecord' so try

    1) Establish context - it needs to know what record is to be displayed in the screen.

    var AddressID = Request.QueryString("Key58"); (this returns the ID that I need)

    2) Retrieve the record object using FindRecord

    var AddressRecord = CRM.FindRecord("address", "addr_addressid="+AddressID);

    3) Execute the screen and pass in the record to be displayed.

    CRM.AddContent(myBlock.Execute(AddressRecord));

    4) Generate the HTML and send to the browser

    Response.Write(CRM.GetPage());

  • Michele

    The tasks that the page need to do are

    1) Establish context - it needs to know what record is to be displayed in the screen.

    2) Retrieve the record object using FindRecord

    3) Execute the screen and pass in the recordto be displayed.

    4) Generate the HTML and send to the browser

    So you need to know what record is to be displayed.

  • Jeff...

    Unfortunately, I am not understanding something about how to grab the data for a view/edit page. Just as I thought I was understanding all this, my head blew up!!

    If you recall, you helped me with a list page on an external database. I had a little bit of a curve ball in accessing some list data from the external entity based on the context and the join. You were able to get me on the right track to get a list displayed (Thank you!!!).

    Now I have a similar situation. However, instead of a list block, I want to use a screen block. Based on my understanding, I thought I would be able to switch out the block names and be good to go. However, no data is being returned to my page.

    I have done some additional research on blocks...but I am not seeing or understanding why the code is not working.

    This is the code for the list page that works..

    (Item to note: the external database will only ever have 1 record with the contact information...therefore, every list is only returning one line item.)

    var myBlock = CRM.GetBlock(LocContactsList);

    var AddressID = Request.QueryString("Key58");

    var AddressRecord = CRM.FindRecord("address", "addr_addressid="+AddressID);

    var LocationAlias = AddressRecord.addr_localias;

    var Arg = "alias='"+LocationAlias+"'";

    CRM.AddContent(myBlock.Execute(Arg));

    Response.Write(CRM.GetPage());

    This is what I have in my View/Edit Page...Can you see anything here that would cause my page to not return any data when it returned a record on the list?

    var myBlock = CRM.GetBlock(LocContactsDetailBox);

    var AddressID = Request.QueryString("Key58");

    var AddressRecord = CRM.FindRecord("address", "addr_addressid="+AddressID);

    var LocationAlias = AddressRecord.addr_localias;

    var Arg = "alias='"+LocationAlias+"'";

    CRM.AddContent(myBlock.Execute(Arg));

    Response.Write(CRM.GetPage());

    All that I know for certain is that LocContactsList is an eWareListBlock and LocContactsDetailBox is an eWareEntryGroupBlock.

    Any assistance or further reading you can recommend would be greatly appreciated. Thank you!!