Building selection lists in ASP pages without reference to Meta Data

Hints, Tips and Tricks

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

Building selection lists in ASP pages without reference to Meta Data

  • Comments 18
  • Likes
From time to time you will need to build pages that can not directly be based on a Meta data definition of a screen. For example if you need to construct a page that allows cloning of an entity or perhaps interaction with an external system. The CRM objects allow to you to easily build screens and entries that are unbound to underlying data structures. 

The basic pattern of screen unbound to Meta data looks like this:
  1. Create screen
  2. Create field
  3. Set field properties
  4. Add field to screen
  5. Write block to web
  6. Handle save mode of screen
The following examples will take us through the building of a page that has a form and fields unbound to a record. The page will be in edit mode and when the page is 'saved' the data entered will be written back to the page to demonstrate the passing of unbound data.

The CRM.GetBlock() method allows you to create a block without reference to existing metadata. In the example (1) below you can see two 'block' types being referenced. The 'entrygroup' is the screen. The 'entry' is the field.

Example 1

var customScreenBlock = CRM.GetBlock('entrygroup');
var customTextEntryBlock = CRM.GetBlock('entry');

If we add a field that is unbound to meta data definitions then we will have to set all its relevant properties. The field is entry on an HTML form therefore it will need to know its type, name, length and any default value.

You will need to reference the description in the Developers guide for the eWareEntryBlock Object.

A basic text entry block might look like example (2)

Example 2

with (customTextEntryBlock)
EntryType = 10; //single line text entry
DefaultType = 1
DefaultValue = 'Hello World';
FieldName = 'custom_text'; //field name in HTML form
Caption = 'TextField:';
CaptionPos = CapTop; // CRM caption location constants defined in eWare.js file
maxLength = 60;

The EntryType and DefaultType differ from field type to field type. A date field might look like example (3).

Example 3

var customDateEntryBlock = CRM.GetBlock('entry');
with (customDateEntryBlock)
EntryType = 42; //Date Only
//EntryType = 41; //Date Time
DefaultType = 6; //Current Date
//DefaultType = 14; //Current Date plus 30
FieldName = 'custom_date'; //This names the field;
Caption = CRM.GetTrans('colnames','Comm_DateTime')+':'; //Translation for the column
CaptionPos = CapTop; // caption location constants defined in eWare.js file
NewLine = false;

EntryType then determines the nature of the field. There are a few types which are selection lists. The example (4) below shows how a user selection list can be built. Selection lists need to be 'sized' to control the drop down behaviour.

Example 4

var customUserEntryBlock = CRM.GetBlock('entry');
EntryType = 22
FieldName = 'custom_userid'; //This names the field;
Caption = 'User:';
CaptionPos = CapTop; // caption location constants defined in eWare.js file
Size= 1;
NewLine = false;

This example (5) shows how a team selection list can be added.

Example 5

var customChannelEntryBlock = CRM.GetBlock('entry');
EntryType = 23;
Caption = CRM.GetTrans('ColNames','oppo_Channelid')+':'; //Translation for the column
CaptionPos = CapTop; // caption location constants defined in eWare.js file
FieldName = 'custom_channelid'; //This names the field;
AllowBlank = false
Size = 1;
NewLine = true;

The examples 4 & 5 show how the selection lists are created automatically using the existing user and team list behaviour. We can build selection lists that use existing pull down values very easily. In the example (6) below we might need to add a list of countries. This has been done by using the LookUpFamily property. The LookUpFamily is the translation capt_family that groups the selection values (capt_code) together.

Example 6

var customSelectionEntryBlock = CRM.GetBlock('entry');
EntryType = 21 //Selection from Lookup
AllowBlank = true //Relevant when EntryType = 21, adds blank option to drop down list.
Caption = eWare.GetTrans('ColNames','addr_country')+':'; //Translation for the column
CaptionPos = CapTop; // eWare caption location constants defined in eWare.js file
//MultipleSelect = true; //can more than one value be selected?
FieldName = 'custom_country'; //This names the field;
LookUpFamily = "addr_country" //uses family for selection items.
RemoveLookup('UK') //removes list item from selection
Size = 1;
NewLine = false;

Selection however might need to be added into the system that are based on the application data held in the system rather that the meta data. For example a selection list referencing the marketing campaigns. The example (7) below shows how we can use the eWareRecord object to produce the list of data for the selection, and how the eWareEntryBlock can be used to position and control the field in the form. But it also shows that we will need to use custom HTML to assemble the custom selection list.

Note: Because we are forcing our own selection list into the field using the EntryBlock caption property we should take care to make the field ReadOnly.

Example 7

var customAppDataSelectionEntryBlock = CRM.GetBlock('entry');

var CustomField = '<SELECT class=EDIT size=1 name="custom_campaign">'
var CampaignRecords = CRM.FindRecord('campaigns','camp_deleted is null');
CampaignRecords.OrderBy = 'camp_name' //ASC and DESC can be used.
while (!CampaignRecords.eof) //eof checks for end of data and instantiates query
CustomField+='<OPTION Value="'+CampaignRecords.camp_campaignid+'">'+CampaignRecords.camp_name+'</OPTION>'
CustomField +='</SELECT>';

ReadOnly = true; //see note above.
NewLine = false;
Caption = CRM.GetTrans('ColNames','Camp_Name')+':<BR>'+CustomField

The form can be build by adding the entryblocks into the entrygroup as in the example(8) below:

Example 8

Title='Custom Form';

A form by default will be drawn in View mode. This is inappropriate for a form which is unbound to data and therefore does not have an existing associated record. We should have the form appear in edit mode using the switch code in the below example. The switch code would normally be placed towards the top of the ASP code. This will be shown in the completed example.

Example 9

if (CRM.Mode == View)
CRM.Mode = Edit;

The page is assembled and written using the code below in example 10. If this page had been bound to a record then the eWareRecord object would normally be passed into the Execute method of the EntryGroupBlock. This would then automatically handle the move from view, to edit, to save modes. We have already discussed how we need to start the form in Edit mode, but we also need to consider what happens when the 'Save' button is clicked. We will need to handle the submitted data when the form is changed to 'Save' mode.

The fields that we have added in the above example will be available in the standard ASP Form collection. They exist as name/value pairs using the name set by the EntryBlock's FieldName property.

Note: the selection list created in example 7 does not have its field name set using the FieldName property.

Example 10

Response.Write(CRM.GetPage()); //use default tab group

if (CRM.Mode == Save)

  • Hi there,

    Thank you for your post.

    I tried implementing example 7, but somehow Im still having the same issue. the combo box wasn't created.

    the code is below:


    var CustomField = '<SELECT class=EDIT size=1 name="case_materielsid">'

    var MaterielsRecords = eWare.FindRecord('Materiels','mate_deleted is null');

    MaterielsRecords.OrderBy = 'mate_name' //ASC and DESC can be used.

    while (!MaterielsRecords.eof) //eof checks for end of data and instantiates query


    CustomField+='<OPTION Value="'+MaterielsRecords.mate_materielsid+'">'+MaterielsRecords.mate_name+'</OPTION>'



    CustomField +='</SELECT>';



    ReadOnly = true; //see note above.

    NewLine = false;

    Caption = eWare.GetTrans('ColNames','mate_Name')+':<BR>'+CustomField


    Where exactly i should put this code? I tried putting it in the screen's .inc file.


  • OK so i succeeded in transforming it into a combo box by putting the code in the create script of the field. however, i want to do further filtering on this combo box by adding a condition on the logged-in company so the code becomes something like this:

    eWare.FindRecord('Materiels','mate_deleted is null and mate_companyid = ' + ?? );

    Now how can I get the logged in company in the Self service into the create script in the CRM customization screen?


  • In a self service page you can find out the company details quite easily

    var intRecordId = CRM.VisitorInfo("visi_personid");

    var PersonRecord = CRM.FindRecord('person','pers_personid='+intRecordId);

    var CompanyRecord = CRM.FindRecord('company','comp_companyid='+PersonRecord.pers_companyid);

  • Agreed,  But I used the code in the Create Script of the field in the Sage CRM (Administration > Customization Cases > Screens) not in the self service page

  • You could define the code in the ASP page and then assign it to the entry block using the CreateScript property


    myEntryBlock.CreateScript = "if (CurrentUser.user_logon=='Admin'){Hidden=true}";

  • OK I defined it in the ASP page and its working perfectly now.

    Just one more question:  can I place the field anywhere i want in the form or it should be always the last field?

  • When you add the entryblock you can determine where it goes

    var myEntryBlock = myBlock.AddEntry("fieldName",3,true);

    The second parameter is the positional value.


  • Thank you very very much. I really appreciate your help!

  • Hi Jeff,

    I have this kind of entry working but I am not being able to make use of validation scripts nor onchange scripts of other fields.

    Is there any way to make them work with this kind of selection list based on Adv Sel Search fields?

  • Eduardo

    Does this not work?

    with (myEntryBlock)


     OnChangeScript = "window.alert('field changed')";

     CreateScript = "if (CurrentUser.user_logon=='Admin'){Hidden=true}";

     ValidateScript = "if (Values('fieldname')<=20){Valid=false;ErrorStr='Error';}";


  • Thank you Jeff! I was Misspelling ValidateScript "ValidationScript" in conjunction with other things.  now it works

  • Do you have examples of this in c# using the .net sdk?

  • Sorry - I don't have anything handy.  I do remember there was some discussion in the .NET forum some time ago.  I'm not going to be able to look at this immmediately as I am pretty maxed out but do nag me again about this in about 2 weeks when I should have more time available to write something up.

  • Jeff, I've tried adding a date time field EntryType = 41; //Date Time using your example above.

    When changing the time i get:

    An error has occurred in the script on the page.

    Unable to get the value of the property 'value': object is null or undefined

    My crm version is Version 7.1.f S  is this normal behaviour?

  • Jeff...

    Does this still work in 7.2?  I tried it and I am not getting it to work.  I am going to go back and double check everything to see if I missed something or if I misspelled something.  However, it occurred to me that perhaps this is done differently in 7.2.

    I am trying to create an ASP page with two text boxes without reference to Meta Data.  Therefore, I am using example 1, example 2 and example 10.  I know that I need to go back and add example 9 (switch view mode).  I just get a blank screen in Sage CRM when I view it.

    Thank you for your assistance!