sage crm developers course implementing screen based rules (1)

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

Upload: shauna-briggs

Post on 05-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

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

Sage CRM Developers Course

Implementing Screen Based Rules (1)

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

Page 3: Sage CRM Developers Course Implementing Screen Based Rules (1)

Agenda

Different Types of Rules

General Development Tips

Create Script

Page 4: Sage CRM Developers Course Implementing Screen Based Rules (1)

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.

Page 5: Sage CRM Developers Course Implementing Screen Based Rules (1)
Page 6: Sage CRM Developers Course Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)
Page 8: Sage CRM Developers Course Implementing Screen Based Rules (1)

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

Page 9: Sage CRM Developers Course Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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): [email protected]

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

Page 11: Sage CRM Developers Course Implementing Screen Based Rules (1)

Accessing CurrentUser Properties

To prove what CurrentUser properties are available use this create scriptValid = 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');

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

Page 12: Sage CRM Developers Course Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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

}

Page 14: Sage CRM Developers Course Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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

Page 17: Sage CRM Developers Course Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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 Implementing Screen Based Rules (1)

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

Page 21: Sage CRM Developers Course Implementing Screen Based Rules (1)

Example use of Caption ‘trick’

Page 22: Sage CRM Developers Course Implementing Screen Based Rules (1)

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;

}

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 Implementing Screen Based Rules (1)

Field Level Scripting on Columns

Field level scripting for grid columns.

Custom Content available

New 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 Implementing Screen Based Rules (1)

Q&AQ&A

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

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