<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.11/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.11/ http://www.mediawiki.org/xml/export-0.11.xsd" version="0.11" xml:lang="en">
  <siteinfo>
    <sitename>Sage CRM Knowledge Base</sitename>
    <dbname>crmtoget_mwkb267</dbname>
    <base>https://kb.crmtogether.com/index.php?title=Screen_Customisation</base>
    <generator>MediaWiki 1.42.3</generator>
    <case>first-letter</case>
    <namespaces>
      <namespace key="-2" case="first-letter">Media</namespace>
      <namespace key="-1" case="first-letter">Special</namespace>
      <namespace key="0" case="first-letter" />
      <namespace key="1" case="first-letter">Talk</namespace>
      <namespace key="2" case="first-letter">User</namespace>
      <namespace key="3" case="first-letter">User talk</namespace>
      <namespace key="4" case="first-letter">Sage CRM Knowledge Base</namespace>
      <namespace key="5" case="first-letter">Sage CRM Knowledge Base talk</namespace>
      <namespace key="6" case="first-letter">File</namespace>
      <namespace key="7" case="first-letter">File talk</namespace>
      <namespace key="8" case="first-letter">MediaWiki</namespace>
      <namespace key="9" case="first-letter">MediaWiki talk</namespace>
      <namespace key="10" case="first-letter">Template</namespace>
      <namespace key="11" case="first-letter">Template talk</namespace>
      <namespace key="12" case="first-letter">Help</namespace>
      <namespace key="13" case="first-letter">Help talk</namespace>
      <namespace key="14" case="first-letter">Category</namespace>
      <namespace key="15" case="first-letter">Category talk</namespace>
    </namespaces>
  </siteinfo>
  <page>
    <title>Screen Customisation</title>
    <ns>0</ns>
    <id>21</id>
    <revision>
      <id>287</id>
      <parentid>256</parentid>
      <timestamp>2018-08-29T15:59:55Z</timestamp>
      <contributor>
        <username>Crmtogetherkb</username>
        <id>1</id>
      </contributor>
      <origin>287</origin>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text bytes="3769" sha1="hl22yviqxxiunsmjutkpkalza8uxhkm" xml:space="preserve">
To add in script code from a page set the link as follows

  &lt;script src="../custompages/pathtofile/commlist.js" type="text/javascript" language="JavaScript"&gt;&lt;/script&gt;

To enumerate block entries (Ref: https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2007/11/28/setting-screen-properties-within-a-multiblock-asp-page-using-the-com-api.aspx)

  //Set EntryBlock properties for an EntryGroup Block using an Enumerator
  var myE = new Enumerator(myBlock);
  while (!myE.atEnd())
  {
     myEntryBlock = myE.item();
     myEntryBlock.ReadOnly = false;
     myEntryBlock.Required = false;
     myE.moveNext();
  }


----
Useful menthod to parse the querystring from the client

Ref: http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx

  function getQuerystring(key, default_)
  {
    if (default_==null) default_="";
    key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&amp;]"+key+"=([^&amp;#]*)");
    var qs = regex.exec(window.location.href);
    if(qs == null)
      return default_;
    else
      return qs[1];
  }


----

To break up a screen visually create a dummy field and add in

  &amp;lt;HR border=1&amp;gt;

as the caption

----

Adding new phone and email addresses to screens

Go into translations and look up Link_CompPhon (or link_prefixphone/email)

This shows you a list which you can add to by adding new translations


----

Custom validation on a screen

If you have a custom method for validating data and you wish to code this in your ASP page (or outside of the validation script area) then you need to do something like the following

  Entry = ctproductblock.GetEntry("productname");
  if(!validate(Request.Form("productcode")))
  {					
      Entry.ValidateScript = "Valid=false;ErrorStr='Product code already exists';"; 
  }

if our sample above the validate() method checks that the product code is unique.

Ref: https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2007/07/22/server-side-validation-and-asp-pages.aspx


----

Add a hyper link to a field on a screen - Custom SSA fields can only be hyperlinked throught the UI for lists and not for screens so here we have a workaround.

Ref: https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2010/07/06/hyperlinking-to-a-parent-custom-entity-from-a-search-select-advanced-field.aspx

*Within CRM open the screen
*Select the field
*Within the "create script" textbox enter in the following (update as per your custom entity first)

  var intRecordId = CRM.GetContextInfo("opportunity","oppo_projectid");
  var strURL = CRM.URL("project/projectsummary.asp")+"&amp;proj_projectid="+intRecordId;
  var strCaptionText = "Project";
  var strFullCaption = "&lt;a href="+strURL+"&gt;"+strCaptionText+"&lt;/a&gt;:";
  Caption = strFullCaption;

This sets the field "Caption" to be a hyperlink so it is not ideal but works as a quick "fix"


----

Field Validate scripts - Values vs values - (seen in 7.1)

This threw me a few times....within field validate scripts the "values" object starts with a lowercase v

  ErrorStr="testx="+values("case_ct_supportemail");

Anything in values only comes from the screen so if the field referenced is not on the screen then it wont be in values - you would then query the db to get that value.


----

Ajax Request

function _makeRequestGET(path, callback)
{
  _dbg("_makeRequestGET path:"+path);
  
    $.ajax({
        type: "Get",
        url: path,
        success: function (data, text) {
            callback(data);
        },
        error: function (request, status, error) {
            alert("ERROR in _makeRequestGET: "+request + " status:"+ status + " path:"+ path);
        }
    });
}</text>
      <sha1>hl22yviqxxiunsmjutkpkalza8uxhkm</sha1>
    </revision>
  </page>
</mediawiki>
