Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sage CRM Developers Course

Similar presentations


Presentation on theme: "Sage CRM Developers Course"— Presentation transcript:

1 Sage CRM Developers Course
Implementing Screen Based Rules (1)

2 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 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)

3 Agenda Different Types of Rules General Development Tips Create Script

4 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.

5

6 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?

7

8 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

9 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 Sage CRM MME uses a concept of system context that allows it to keep tract of what entities within the current session are being used. This is part of the state information that is recorded within the URLs that are passed into the eware.dll to generate the pages. The system will always be in context of the current logged on user, & as you view data so the context will change. For example whilst on a person's summary screen you will be in the context of the user, the company, & the person. Within Validation scripts (& table/entity & workflow scripts) this context is accessed via the eWare object.

10 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): user_fax (Fax): user_ address ( ): user_per_admin (Administration): 3 user_resource (Resource): False user_externallogonallowed (External Logon Allowed): True user_primaryterritory (Home Territory): 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 If you add fields to the user table via the interface then these new fields will be added to the CurrentUser object, both the client side and the serverside object. Test this with: <script> var x for (x in CurrentUser) { document.write(x); }

11 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_ Address'); or DefaultValue = CRM.GetContextInfo('user','User_ Address');

12 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. Valid is a system variable with the default value of true. Within CreateScripts, if the value of Valid is set to false then the contents of ErrorStr is output to the calling client page. e.g if (CurrentUser.user_primarychannelid != 1) { Valid = false; ErrorStr = 'Hello World' } Within CreateScripts this is primarily useful for debugging and for ‘warning’ rules.

13 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'; }

14 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’)

15 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_ty pe"); if (CurrentUser.user_primarychannelid == 3 && strType == 'Customer') { ReadOnly = false; } else { ReadOnly = true; }

16 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

17 Values() Usage Values() FormValues() Reassign Values
Access QueryString Create Script Can see data in form in View mode not Edit or Save Can see data in form in Save mode not View or Edit No both Values () – yes FormValues - no Validate Script All submitted data defined in blocks used in form Table level Script Only data in entity screen block e.g. company not address info Yes Values() No FormValues() -errors Values () – no

18 Using Mode in a create script
if(Values("Act")==200||Values("Act")==520||Values("_actionid")==201) { var strTwitterName = Values('comp_twittername'); var strUrl =" Caption = "<a href="+strUrl+" target=new>"+CRM.GetTrans("colnames","comp_twittername")+"</a>:"; }

19 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) { var strTwitterName = Values('comp_twittername'); var strUrl =" Caption = "<a href="+strUrl+" target=new>"+CRM.GetTrans("colnames","comp_twittername")+"</a>:"; }

20 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 +="<a href="+CRM.URL(185)+" target=EWARE_MID CLASS=TOPSUBHEADING>"+caseRecord.RecordCount+"</a>"; Caption +="</td></tr></table>" ;

21 Example use of Caption ‘trick’

22 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="; Caption = "<img width=100 src='"+pictureURL+"'>"; } else Caption = "No Image Available"; 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

23 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; }

24 Q&A

25 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 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)

26 Visit the Sage CRM Ecosystem at www.sagecrm.com
Facebook: Sage CRM Twitter: wwwsagecrmcom LinkedIn: Sage CRM (Official Group) YouTube: wwwsagecrmcom


Download ppt "Sage CRM Developers Course"

Similar presentations


Ads by Google