260 likes | 448 Views
Sage CRM Developers Course. Implementing Screen Based Rules (1) . Looking ahead to the classes. DP01: Introduction to the Development Partner Program DP02: Entities and the Data Model (Part 1 of 2) DP03: Entities and the Data Model (Part 2 of 2)
E N D
Sage CRM Developers Course Implementing Screen Based Rules (1)
Looking ahead to the classes • DP01: Introduction to the Development Partner Program • DP02: Entities and the Data Model (Part 1 of 2) • DP03: Entities and the Data Model (Part 2 of 2) • DP04: Implementing Screen Based Rules (Part 1 of 2) • DP05: Implementing Screen Based Rules (Part 2 of 2) • DP06: Screen and User Independent Business Rules • DP07: Workflow (Part 1 of 2) • DP08: Workflow (Part 2 of 2) • DP09: Using the API Objects in ASP Pages (Part 1 of 2) • DP10 : Using the API Objects in ASP Pages (Part 2 of 2) • DP11: Using the Component Manager • DP12: Programming for the Advanced Email Manager • DP13: Using the Web Services API • DP14: Using the Web Services API (Part 2 of 2) • DP15: Coding the Web Self Service COM API (Part 1 of 2) • DP16: Coding the Web Self Service COM API (Part 2 of 2) • DP17: Using the .NET API (Part 1 of 2) • DP18: Using the .NET API (Part 2 of 2)
Agenda • Different Types of Rules • General Development Tips • Create Script
Rules are of different types • Restrictive (and Informative) • Blocking an action and explaining why. • Corrective (and Informative) • Changing data to within tolerance and explaining why. • Manipulative • Automatic change to data, triggering of other behaviour without prompting.
Create Script • What are the Objects Available? • What is the Scope of Effect? • How can the Valid, ErrorStr system variables help? • What are the Values(), FormValues() objects? • How can we handle screen mode? • What is the difference between coding in a screen field versus a column?
The Scripting Language Used • Jscript is used for all internal scripting Field Level (Create, Validate) Table Level • Jscript Implicitly used for onChange scripts • The objects that are available for reference depend on where the code is run. In an ASP Page In the Browser ‘Inside’ the Application server as Internal Script Objects that exist in the browser will not exist in ASP pages Objects that exist in ASP page will not exist in Internal script Core Jscript objects and syntax are always available Can instantiate ActiveX objects
Context Builds like Snowball • Context passed in URL • Key0 • Current Context • Key1 • Company • Key2 • Person • Key6 • Communication • Key7 • Opportunity • Session ID provides implicit User context information
CurrentUser Properties • user_displayname (User Template): System Administrator • user_pwdprofile (Administration): 3 • user_userid (User): 1 • user_primarychannelid (Primary Team): 5 • user_logon (User Name): Admin • user_lastname (Last Name): Administrator • user_firstname (First Name): System • user_language (Language): US • user_department (Department): IS • user_phone (Phone): 353 1 612 3456 • user_fax (Fax): 353 1 612 3444 • user_emailaddress (E-mail): admin@panoplytech.com • user_per_admin (Administration): 3 • user_resource (Resource): False • user_externallogonallowed (External Logon Allowed): True • user_primaryterritory (Home Territory): -2147483640 • user_isterritorymanager (Territory Manager): • user_territoryprofile (Profile Name): 1 • user_per_user (Info Admin User Rights): True • user_per_product (Info Admin Product Rights): True • user_per_currency (Info Admin Currency Rights): True • user_per_data (Info Admin Data Rights): True • user_offlineaccessallowed (PDA/WAP Access): True • user_rollupto (Forecasting - Reports To): • user_per_customise (Info Admin Customize): True • user_minmemory (Min memory for SQL to use on client (MB)): • user_maxmemory (Max memory for SQL to use on client (MB)): • user_title (Title): ACCPAC CRM System Admin • user_location (Location): Dublin • user_deskid (Desk Location): 5/234A • user_per_infoadmin (Info Admin Rights): • user_device_machinename (Device Name): • user_per_solutions (Solutions): • user_offlinesecurity (Allow Offline Access): • user_istemplate (Template): N • user_templatename (Template Name): • user_webserviceenabled (Allow Web Service Access): true • user_masterpersid (Hosting Master ID): • user_lastserver (undefined): • user_enabledonotreprice (Enable Overwrite price): • user_prf (undefined): dd/MM/yyyy
Accessing CurrentUser Properties • To prove what CurrentUser properties are available use this create script Valid = false; ErrorStr =''; var recCaption var x for (x in CurrentUser) { recCaption = CRM.FindRecord("custom_captions","capt_code = '"+x+"'"); ErrorStr += x +' ('+recCaption.capt_us+'): '+CurrentUser[x]+'<br>'; } • To access a User property not available within CurrentUser object: Valid = false; ErrorStr = CRM.GetContextInfo('user','User_EmailAddress'); or DefaultValue = CRM.GetContextInfo('user','User_EmailAddress');
Debugging Scripts • Any code that is executed server side (but NOT ASP pages) can make use of the following system variables: • Valid • ErrorStr if (CurrentUser.user_primarychannelid != 1) { Valid = false; ErrorStr = 'Hello World‘ } • NOTE: In Create Scripts Valid=false will not interrupt the commit process.
Example Warning Rule • Warning Rule • For example, a Create script on case screen: var comp_slaid=CRM.GetContextInfo('Company','comp_slaid'); if (!comp_slaid) { Valid = false; ErrorStr ='A case may not be created for a customer without an SLA'; }
CreateScripts & Entry Properties • DefaultValue Only as record is created or in a workflow rule. Outside of a workflow if the record exists then is ignored. • Can not change field entry type (see documentation) in create scripts • Other Properties ReadOnly = false; Hidden = false; Caption = ‘Field Name'; CaptionPos = 0 Required = true; DefaultValue = 'Sage CRM'; Size = 30; maxLength = 60; Width = '1'; Height = '1'; • Methods RemoveLookUp(‘Sybase’)
Interaction with Field Level Security • Field Level Security • A code-free approach to granting or denying read and write permissions for individual fields on a screen. Access rights can be specified on the level of individual users, teams, and profiles. • This code free approach doesn't however cover all situations. For example if there is a business rule that states "Only Support team members may change a company SLA field when the company is of type 'Customer'". Then we can't use the Field Level Security.Here we can only implement this rule with field level scripting. • In the main entry screen for the company (CompanyBoxLong) we can add a onCreate script to the Comp_SLAId field.var strType = CRM.GetContextInfo("company","comp_type");if (CurrentUser.user_primarychannelid == 3 && strType == 'Customer'){ReadOnly = false;}else{ReadOnly = true;}
Mode, & Create Scripts • CRM Screens can exist in different ‘Modes’ View Edit Save • May want to hide a field based upon the eWare mode so that it is only available in View mode? • In ASP page can use CRM.Mode. Not available in internal script Need to use Act code and hidden form variables
Using Mode in a create script • if(Values("Act")==200||Values("Act")==520||Values("_actionid")==201) • { • var strTwitterName = Values('comp_twittername'); • var strUrl ="http://twitter.com/"+strTwitterName; • Caption = "<a href="+strUrl+" target=new>"+CRM.GetTrans("colnames","comp_twittername")+"</a>:"; • }
Understanding how the mode is Checked • This rule changes the caption of a field to include the URL for a external system. The script will change the Caption only when the screen is in either View mode or Save mode and not edit mode. • Act==200 checks if on summary screen • Act==520 check if come from recent list • _actionid==201 Checks if returned to view from edit mode. • This is a hidden form value specific to the company summary screen. • if(Values("Act")==200||Values("Act")==520||Values("_actionid")==201) • { • varstrTwitterName = Values('comp_twittername'); • varstrUrl ="http://twitter.com/"+strTwitterName; • Caption = "<a href="+strUrl+" target=new>"+CRM.GetTrans("colnames","comp_twittername")+"</a>:"; • }
Another use of the Caption Property • Create Scripts can use server side objects. • Can generate HTML and redefine existing field Caption • TIP: This can be used to create new Client Side objects • Easy use can be to add a ‘Dummy’ field. • Note: Inserted as part of the <FORM>. • var oppoRecord = CRM.FindRecord("opportunity","oppo_status='In Progress' and oppo_primarycompanyid="+CRM.GetContextInfo("company","comp_companyid")); • var caseRecord = CRM.FindRecord("cases","case_status='In Progress' and case_primarycompanyid="+CRM.GetContextInfo("company","comp_companyid")); • Caption = "<Table border=0><tr><td align=right class=topcaption>"; • Caption +=CRM.GetTrans("Tabnames","Opportunities"); • Caption +=":</td><td class=topheading>"; • Caption +="<a href="+CRM.URL(184)+" target=EWARE_MID CLASS=TOPSUBHEADING>"+oppoRecord.RecordCount+"</a>"; • Caption +="</td></tr><tr><td align=right class=topcaption>" ; • Caption +=CRM.GetTrans("Tabnames","Cases"); • Caption +=":</td><td class=topheading>"; • Caption +="<a href="+CRM.URL(185)+" target=EWARE_MID CLASS=TOPSUBHEADING>"+caseRecord.RecordCount+"</a>"; • Caption +="</td></tr></table>" ;
Create Script on ‘Image’ field if(Values("Act")==220||Values("Act")==520) { var SID var strPath = eWare.URL(220); //the system action 220 is for the person summary screen var arrayFullKeys = strPath.split("?"); //arrayFullKeys[0] contains path up like "/crm/eware.dll/Do" var arrayKeys = arrayFullKeys[1].split("&"); for (var i=0;i<arrayKeys.length;i++) { var arrayValue = arrayKeys[i].split("="); if (arrayValue[0].toLowerCase()== "sid") { SID = arrayValue[1]; } } var myRecordId = eWare.GetContextInfo('person','pers_personid'); var myRecord = eWare.FindRecord('library',"libr_type='Image' and libr_personid ="+myRecordId); var pictureURL = arrayFullKeys[0]+"/"; if (!myRecord.eof) { //pictureURL += custom_sysparams.parm_value; pictureURL += myRecord.Libr_FilePath; pictureURL += myRecord.Libr_FileName; pictureURL += "?SID="; pictureURL += SID; pictureURL += "&Act=1282&Mode=0&FileName="; pictureURL += myRecord.Libr_FilePath; pictureURL += myRecord.Libr_FileName; Caption = "<img width=100 src='"+pictureURL+"'>"; } else { Caption = "No Image Available"; } } else { Hidden =true; } Assumptions 1 picture only is stored for an individual Picture is upload via the library Image is of library type 'image'. Image url will consist of... libraryfilename path associated with person in person record. library directory path
Field Level Scripting on Columns • Field level scripting for grid columns. • Custom Content available • New property in GridColumnBlock • visible = true|false • Ignored in ASP pages • Contextual Info available • E.g. Can check for presence/absence of CompanyID etc if(CRM.GetContextInfo(‘company’,’comp_companyid’) { Visible = false; }
Looking ahead to the classes • DP01: Introduction to the Development Partner Program • DP02: Entities and the Data Model (Part 1 of 2) • DP03: Entities and the Data Model (Part 2 of 2) • DP04: Implementing Screen Based Rules (Part 1 of 2) • DP05: Implementing Screen Based Rules (Part 2 of 2) • DP06: Screen and User Independent Business Rules • DP07: Workflow (Part 1 of 2) • DP08: Workflow (Part 2 of 2) • DP09: Using the API Objects in ASP Pages (Part 1 of 2) • DP10 : Using the API Objects in ASP Pages (Part 2 of 2) • DP11: Using the Component Manager • DP12: Programming for the Advanced Email Manager • DP13: Using the Web Services API • DP14: Using the Web Services API (Part 2 of 2) • DP15: Coding the Web Self Service COM API (Part 1 of 2) • DP16: Coding the Web Self Service COM API (Part 2 of 2) • DP17: Using the .NET API (Part 1 of 2) • DP18: Using the .NET API (Part 2 of 2)