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".
Parents
  • Michele

    The tasks we need to do remain the same,

    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

    The first line gets the screen we wish to use to display the LOCATIONSITE record. I assume that this screen is based on that table. MAKE SURE THAT YOU HAVE REMEMBERED TO INCLUDE FIELDS IN THE SCREEN.

    var LocContact1Block = CRM.GetBlock('LocContactsDetailBoxC1');

    The next line gets our current context. This key will be the primary key value for the address record.

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

    We can then find the address record.

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

    The address record is the 'child' of the LOCATIONSITE. There is a foreign key on the Address that looks up to the LOCATIONSITE

    var AddressAlias = AddressRecord.addr_smalias;

    This value can then be used to find the parental LOCATIONSITE. I assume that the ALIAS field value for LOCATIONSITE is either a primary key or an alternate (unique) key.

    var LocContactRecord = CRM.FindRecord("LOCATIONSITE","ALIAS="+"'AddressAlias'");

    The SQL that this generates will be shown in the log. This can be used to prove the data that is returned.

    The record can then be added to the screen and the HTML generated.

    CRM.AddContent(myLocContact1Block.Execute(LocContactRecord));

    And the page returned to the browser.

    Response.Write(CRM.GetPage());

Comment
  • Michele

    The tasks we need to do remain the same,

    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

    The first line gets the screen we wish to use to display the LOCATIONSITE record. I assume that this screen is based on that table. MAKE SURE THAT YOU HAVE REMEMBERED TO INCLUDE FIELDS IN THE SCREEN.

    var LocContact1Block = CRM.GetBlock('LocContactsDetailBoxC1');

    The next line gets our current context. This key will be the primary key value for the address record.

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

    We can then find the address record.

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

    The address record is the 'child' of the LOCATIONSITE. There is a foreign key on the Address that looks up to the LOCATIONSITE

    var AddressAlias = AddressRecord.addr_smalias;

    This value can then be used to find the parental LOCATIONSITE. I assume that the ALIAS field value for LOCATIONSITE is either a primary key or an alternate (unique) key.

    var LocContactRecord = CRM.FindRecord("LOCATIONSITE","ALIAS="+"'AddressAlias'");

    The SQL that this generates will be shown in the log. This can be used to prove the data that is returned.

    The record can then be added to the screen and the HTML generated.

    CRM.AddContent(myLocContact1Block.Execute(LocContactRecord));

    And the page returned to the browser.

    Response.Write(CRM.GetPage());

Children
No Data