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".
  • Thank you Jeff!!!

    I think I got it! :-) After reviewing your reply, it looked like the theory of what I was doing was on track so that is reassuring.

    I was reviewing the logs yesterday and I thought the correct select statement was coming through. (There is a lot of data to look through even if you rename the log file and let it regenerate a new one!!)

    I decided to look at the select statement from the list block that is returning data and compare it to the select statement from the screen block that I am not getting data on. They were not matching up even though I thought I had used the correct syntax in the definition of my LocContactRecord.

    I had this in the non functioning code...

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

    I changed it to this...

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

    Those two lines sorta look the same...but the query string is different. For the query string, I pasted in exactly what we had on the list block for the Arg. And volia! Data!!! :-)

    I feel better that it was syntax, at least I did understand what I was doing, the syntax tripped me up! Thank you for helping me see that!!!

    P.S. This part of your reply made me laugh... MAKE SURE THAT YOU HAVE REMEMBERED TO INCLUDE FIELDS IN THE SCREEN. (I know it had to be asked.)

    Now I have to do some other stuff with this screen ... fingers crossed that I don't have to call out ... Jeff .. Help!!!

    As always...Thank you, Thank you, Thank you!!! For your assistance!

  • Jeff ...

    I updated the page code...but I am still not getting a record returned. Here is the code I am using...I don't get an error...but I don't get a record either. Does this appear to be correct? I can get a record for a list so I know there is a record...just not sure what I am doing wrong...

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

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

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

    var AddressAlias = AddressRecord.addr_smalias;

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

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

    Response.Write(CRM.GetPage());

    LOCATIONSITE is my external table name

    ALIAS is the field on the external table I am using to match the data

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

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

  • Thanks Jeff...

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

    I had a feeling it was going to be something around the Arg. However, I could not find enough information to help me get that straight.

    If I understand what you are saying...'Arg' can only be used with a ListBlock. If I am using a screen block, I need to pass my record.

    What is going to trip me up here is that the AddressRecord is not the record that I need to display, I need to display the Contacts associated with that AddressRecord from an external table (I didn't design how these connect..however, that is the connection I have to work with. :-)). The system is designed so that when you are working with the locations, the user is in the context of the Address entity. Therefore, the addr_addressID is what you can pull out of the URL. On the address record in CRM is a field for the location alias. The alias is the unique identifier in the external table for the record I want.

    Therefore, I am getting to the record this way ---> Address ID ---> addr_localias ---> addr_localias = alias ---> alias = myRecord in the External database.

    Since I believe I understand that I need to pass a record not an Arg to the screen block, I need to figure out how I filter that record to the actual record that I want. I am sure that I have seen how to do this before...just don't remember how. If I were writing SQL, I could do it.

    I am off to do more research on FindRecord and I am hoping that is the direction I need to go. If I am headed in the wrong direction, please let me know and shove me in a different one!

    Thank you for your assistance!!!

  • Thanks Jeff. I thought I covered all those steps...but still no record.

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

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

    2) Retrieve the record object using FindRecord

    Retrieve the record ---> var AddressRecord = CRM.FindRecord("address", "addr_addressid="+AddressID);

    var LocationAlias = AddressRecord.addr_localias;

    Join it to the context ---> var Arg = "alias='"+LocationAlias+"'";

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

    Execute the screen/pass the record (Arg) ---> CRM.AddContent(myBlock.Execute(Arg));

    4) Generate the HTML and send to the browser

    Response.Write(CRM.GetPage());

    The code all works fine for the list block but not the screen block. Your message appears to say that I need to tell it what record. However, I feel I did in item 2 and then I passed it in item 3. If it worked for the list block should it not also work for the screen block? I must not be understanding something that I thought I understood. Am I on the right track?

    Any assistance you can provide would be greatly appreciated.

    Thanks!