sage crm developers course

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

Upload: keilah

Post on 25-Feb-2016

47 views

Category:

Documents


4 download

DESCRIPTION

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) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Sage CRM Developers Course

Sage CRM Developers Course

Implementing Screen Based Rules (1)

Page 2: Sage CRM Developers Course

Looking ahead to the classes

DP01: Introduction to the Development Partner ProgramDP02: 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 RulesDP07: 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 ManagerDP12: Programming for the Advanced Email ManagerDP13: Using the Web Services APIDP14: 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)

Page 3: Sage CRM Developers Course

Agenda

Different Types of RulesGeneral Development TipsCreate Script

Page 4: Sage CRM Developers Course

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.ManipulativeAutomatic change to data, triggering of other behaviour without prompting.

Page 5: Sage CRM Developers Course
Page 6: Sage CRM Developers Course

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?

Page 7: Sage CRM Developers Course
Page 8: Sage CRM Developers Course

The Scripting Language Used

Jscript is used for all internal scriptingField 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 PageIn the Browser‘Inside’ the Application server as Internal Script

Objects that exist in the browser will not exist in ASP pagesObjects that exist in ASP page will not exist in Internal script

Core Jscript objects and syntax are always availableCan instantiate ActiveX objects

Page 9: Sage CRM Developers Course

Context Builds like Snowball

Context passed in URLKey0– Current Context

Key1– Company

Key2– Person

Key6– Communication

Key7– Opportunity

Session ID provides implicit User context information

Page 10: Sage CRM Developers Course

CurrentUser Propertiesuser_displayname (User Template): System Administratoruser_pwdprofile (Administration): 3user_userid (User): 1user_primarychannelid (Primary Team): 5user_logon (User Name): Adminuser_lastname (Last Name): Administratoruser_firstname (First Name): Systemuser_language (Language): USuser_department (Department): ISuser_phone (Phone): 353 1 612 3456user_fax (Fax): 353 1 612 3444user_emailaddress (E-mail): [email protected]_per_admin (Administration): 3user_resource (Resource): Falseuser_externallogonallowed (External Logon Allowed): Trueuser_primaryterritory (Home Territory): -2147483640user_isterritorymanager (Territory Manager): user_territoryprofile (Profile Name): 1user_per_user (Info Admin User Rights): Trueuser_per_product (Info Admin Product Rights): Trueuser_per_currency (Info Admin Currency Rights): True

user_per_data (Info Admin Data Rights): Trueuser_offlineaccessallowed (PDA/WAP Access): Trueuser_rollupto (Forecasting - Reports To): user_per_customise (Info Admin Customize): Trueuser_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 Adminuser_location (Location): Dublinuser_deskid (Desk Location): 5/234Auser_per_infoadmin (Info Admin Rights): user_device_machinename (Device Name): user_per_solutions (Solutions): user_offlinesecurity (Allow Offline Access): user_istemplate (Template): Nuser_templatename (Template Name): user_webserviceenabled (Allow Web Service Access): trueuser_masterpersid (Hosting Master ID): user_lastserver (undefined): user_enabledonotreprice (Enable Overwrite price): user_prf (undefined): dd/MM/yyyy

Page 11: Sage CRM Developers Course

Accessing CurrentUser Properties

To prove what CurrentUser properties are available use this create scriptValid = false;ErrorStr ='';var recCaptionvar xfor (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');

orDefaultValue = CRM.GetContextInfo('user','User_EmailAddress');

Page 12: Sage CRM Developers Course

Debugging Scripts

Any code that is executed server side (but NOT ASP pages) can make use of the following system variables:ValidErrorStr

if (CurrentUser.user_primarychannelid != 1){Valid = false;ErrorStr = 'Hello World‘}

NOTE: In Create Scripts Valid=false will not interrupt the commit process.

Page 13: Sage CRM Developers Course

Example Warning Rule

Warning RuleFor 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';}

Page 14: Sage CRM Developers Course

CreateScripts & Entry Properties

DefaultValueOnly 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 PropertiesReadOnly = false;Hidden = false;Caption = ‘Field Name';CaptionPos = 0Required = true;DefaultValue = 'Sage CRM';Size = 30;maxLength = 60;Width = '1';Height = '1';

MethodsRemoveLookUp(‘Sybase’)

Page 15: Sage CRM Developers Course

Interaction with Field Level Security

Field Level SecurityA 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;}

Page 16: Sage CRM Developers Course

Mode, & Create Scripts

CRM Screens can exist in different ‘Modes’ ViewEditSave

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 scriptNeed to use Act code and hidden form variables

Page 17: Sage CRM Developers Course

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 () – yesFormValues - no

Validate Script All submitted data defined in blocks used in form

All submitted data defined in blocks used in form

No both Values () – yesFormValues - no

Table level Script Only data in entity screen block e.g. company not address info

All submitted data defined in blocks used in form

Yes Values()No FormValues() -errors

Values () – noFormValues - no

Page 18: Sage CRM Developers Course

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>:";}

Page 19: Sage CRM Developers Course

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 ="http://twitter.com/"+strTwitterName;Caption = "<a href="+strUrl+" target=new>"+CRM.GetTrans("colnames","comp_twittername")+"</a>:";}

Page 20: Sage CRM Developers Course

Another use of the Caption Property

Create Scripts can use server side objects.Can generate HTML and redefine existing field CaptionTIP: This can be used to create new Client Side objectsEasy 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>" ;

Page 21: Sage CRM Developers Course

Example use of Caption ‘trick’

Page 22: Sage CRM Developers Course

Create Script on ‘Image’ fieldif(Values("Act")==220||Values("Act")==520){var SIDvar strPath = eWare.URL(220);//the system action 220 is for the person summary screenvar 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;}

Assumptions1 picture only is stored for an individualPicture is upload via the libraryImage is of library type 'image'.

Image url will consist of...libraryfilenamepath associated with person in person record.library directory path

Page 23: Sage CRM Developers Course

Field Level Scripting on Columns

Field level scripting for grid columns.Custom Content availableNew property in GridColumnBlockvisible = true|falseIgnored in ASP pages

Contextual Info availableE.g. Can check for presence/absence of CompanyID etcif(CRM.GetContextInfo(‘company’,’comp_companyid’){Visible = false;}

Page 24: Sage CRM Developers Course

Q&A

Page 25: Sage CRM Developers Course

Looking ahead to the classes

DP01: Introduction to the Development Partner ProgramDP02: 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 RulesDP07: 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 ManagerDP12: Programming for the Advanced Email ManagerDP13: Using the Web Services APIDP14: 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)

Page 26: Sage CRM Developers Course