Field Level Scripting in Search Screens

Hints, Tips and Tricks

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

Field Level Scripting in Search Screens

  • Comments 2
  • Likes
Imagine the situation where there may be a problem with allowing users to search against a entity with out putting in at least one search criterion. You may find the searching against companies too slow if people do not put in the company name for example.

If we consider the CompanySearchBox used in the system built company find screen we can try and use the different scripting types to help us.

CreateScript in Search Screens

The onCreate has little help as it is not possible to set the properties of fields in a search screen. For example we may try on the comp_type field to set

Required= true;
DefaultValue = 'Customer';

This will not error but the property settings are just ignored.

Note: Setting the system variable Valid=false; will allow you to write out the contents of the ErrorStr system variable.

onChangeScript in Search Screens

This scripting is passed to the browser and works as in other edit screens. In search screens we can use this (with the custom content field) to implement format masks and other rules to ensure that the data submitted for searching follows the business rules.

Validation on Search Screens

This is most useful and I confess that I rather over looked this behaviour until a partner pointed this out to me.

Validation rules are checked on submission of a search screen even though in this case no data is being inserted or updated. For example the code below on the comp_name will ensure that it can't be left blank when searching for companies.

if (!Values("comp_name"))
Valid = false;
ErrorStr = "you must fill in this field";
  • Jeff:  I realize this is an old post.  However, we are having an issue with a search screen and I am hoping you can point me in the right direction.

    The requirement is that when the user selects the comp_type from a drop down list, than another selection box will appear depending on what was selected.  For this requirement the only additional selection boxes appear when the comp_type is supplier or subcontractor.  The scripts that we are using work perfectly when using the companylongbox.  However, when we try to apply the same concept to the companysearchbox.  The script does not appear to work at all.  Meaning that the additional selection boxes are there when the user enters the search and nothing changes when selections in the comp_type box are made.  

    This is the what we have in the OnChange Script area of the comp_type field..


    This is what we have in the Custom Content area of the companysearchbox..

    i have inspected the elements of the comp_type box and the only difference I can see between the two is that for the companylongbox the class indicates VIEWBOX and for the companysearchbox the class indicates SEARCHBODY.

    Is there a different way to hide a box based on the value of another field when using a search screen?

    Any assistance you can provide would be greatly appreciated.


  • Michele

    Client Side scripting can work very well with fields in the Search Screen.

    Consider this

    var myfield = crm.fields("oppo_stage");

    if (myfield.value()=='Cancelled'){crm.fields("oppo_status").collapse()}

    This type of code could be used in an onchange field to hide another.