sage crm developers course

24
Sage CRM Developers Course Entities and the Data Model (Part 1)

Upload: amal

Post on 24-Feb-2016

55 views

Category:

Documents


0 download

DESCRIPTION

Sage CRM Developers Course. Entities and the Data Model (Part 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

Entities and the Data Model (Part 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

How data and record identity is handledRecord Object vs. SQLQuery ObjectRole of Stored ProceduresAllowed Database ChangesMeta Data and Physical Data TypesNew Tables and Fields in CRMLinking to External Database tablesHow and where table data is stored in Meta Data

Page 4: Sage CRM Developers Course

How data and record identity is handledRecord Object vs SQLQuery ObjectRole of Stored Procedures

Page 5: Sage CRM Developers Course

New Sage CRM v7.2 Installs on MS SQL Server use SQL Identity Columns

In Sage CRM v7.1 and earlier Primary Key values were generated and maintained by stored procedures. This was to create common method mechanism between main install and SOLO.SOLO dropped in favour of new Mobile AppsNew installs on SQL Server will now use SQL IdentitiesSignificant performance improvementsNew version of Stored Procedure for existing installsNO Change for Oracle

Page 6: Sage CRM Developers Course

New Installs on MS SQL Server use SQL Identity Columns

SELECT t.TABLE_NAME,c.COLUMN_NAMEFROMINFORMATION_SCHEMA.COLUMNS AS c JOININFORMATION_SCHEMA.TABLES AS tON t.TABLE_NAME = c.TABLE_NAMEWHERECOLUMNPROPERTY(OBJECT_ID(c.TABLE_NAME),c.COLUMN_NAME,'IsIdentity') = 1 ANDt.TABLE_TYPE = 'Base Table'

Page 7: Sage CRM Developers Course

eWare_get_identity_id stored procedure use in QueryObject code

Problems will arise with add-on code that does a direct insert using eware_get_identity_id in Query object. ‘hidden’ or automatic rules within CRM– Validation Rules– Table Level Scripts– ASP and .NET Application ExtensionsRecord object not effected

Page 8: Sage CRM Developers Course

Inserts using QueryObject

Sage CRM v7.1var strSQL = "DECLARE @ret int";strSQL += "EXEC @ret=eware_get_identity_id 'cases'";strSQL += "INSERT cases";strSQL += "(case_caseid, Case_Description, Case_PrimaryCompanyId)";strSQL += "VALUES (@ret, 'abc',10)";var myQuery = CRM.CreateQueryObj(strSQL,"");myQuery.ExecSQL()

Sage CRM v7.2var strSQL = "INSERT INTO Cases";strSQL += "(Case_Description, Case_PrimaryCompanyId)"; strSQL += "VALUES ('abc',10)")";var myQuery = CRM.CreateQueryObj(strSQL,"");myQuery.ExecSQL()

NOTE: Upgraded Systems will still use old ID mechanism.

Page 9: Sage CRM Developers Course

Oracle and Inserts

No equivalent stored procedure in Oracle so there is no safe way of getting ids directly.SEQUENCES are used to control the identities.Sequence created in the CRM database for each table with the name TablePrefix_SEQUENCEEg comp_sequence, pers_sequence etc.Cases and CaseProgress share the same sequence as do Opportunity and OpportunityProgress. Next value from a sequence obtained by calling the NextVal function of the sequence. Returns the next val and increments the sequence.SELECT Comp_Sequence.NextVal from DUAL;NOTE: Does not take into account the rep_ranges table, and therefore is not advised

SOLO allocates Ranges to client machinesHeld in Rep_ranges table.When not using API object you will need to check that data is not going out of range.The process is as followsLook up Range_RangeStart and Range_RangeEnd in Rep_Ranges where Range_TableID is the identifier of the table. TableID is 5 for the Company table.Call SELECT Comp_Sequence.NEXTVAL FROM DUAL to get the next sequence number.If the sequence range is outside the range found in step 1 (which it will be because you dropped the sequence and recreated with a sequence start of 1), then assume that this range has been filled up, so move to the next available range.Ranges are allocated in blocks of 50000, so the first range is 8001 to 58000, the second range is 58001 to 108000, the third range is 108001 to 158000, and so on.Problems may arise if more than 1 process is trying to allocate a new range at the same time. NOTE: Do not run process when CRM is running.NOTE: Accessing the ranges table at the back end is not supported.

Page 10: Sage CRM Developers Course

CRM Components & Database Type

System Variables available in component allows the Install to be checked.Write components to accommodate database type.

//iDatabase - returns the current installed database.// Constants returned// ISQLServer// IOracle

// e.g.// if (iDatabase == IOracle)// {// //Do this;// }

sViewText="CREATE VIEW vMyPhone AS SELECT";

if (iDatabase == IOracle)

{

sViewText = sViewText + " Phon_CountryCode || N ' ' ||Phon_AreaCode || N ' ' || Phon_Number";

}

else

{

sViewText = sViewText + "RTRIM(ISNULL(Phon_CountryCode, '')) + ' ' +RTRIM(ISNULL (Phon_AreaCode, '')) + ' ' + RTRIM(ISNULL(Phon_Number, ''))";

}

sViewText = sViewText + " AS Phon_FullNumber, Phone.* FROM Phone ";

if (iDatabase == IOracle)

{

sViewText = sViewText + ", Custom_Captions WHERE LOWER (TRIM(Phon_Type))= LOWER(TRIM(Capt_Code(+))) AND";

}

else

{

sViewText = sViewText + "LEFT JOIN Custom_Captions ON Phon_Type = Capt_Code WHERE";

}

sViewText = sViewText +" Phon_Deleted IS NULL";

AddView("vMyPhone", "Phone", "This selects all of the phone numbers", sViewText, false, false, false, false, false);

Page 11: Sage CRM Developers Course

ALLOWED DATABASE CHANGESMeta Data and Physical Data Types

Page 12: Sage CRM Developers Course

Business Rules in Database

CRM makes use of physical data types but meta data ‘adds value’Custom_editsSee Developer Guide reference for discussion of EntryBlock.EntryType property in APICRM DOES NOT use constraints within database.When installing CRM the only SQL rule that is written into the tables structure is whether the Primary Key column is NOT NULL.All constraints implemented in application layer.

Page 13: Sage CRM Developers Course

CRM FieldTypes & SQL Server DatatypesCRM Field Type Data TypeProduct intIntelligentSelect nvarcharMultiselect nvarcharDateOnly DatetimeCurrency NumericCurrency_CID IntSearchSelectAdvanced IntMinutes IntCurrencySymbols IntText nvarcharStoredProc nvarcharCheckbox nvarcharPhoneNumber nvarcharMultilineText ntextemailaddress nvarcharWWWURL nvarcharSelection nvarcharUserSelect IntTeamSelect IntInteger intNumeric numericDateTime datetime

Page 14: Sage CRM Developers Course

How and where table data is stored in Meta Data

Page 15: Sage CRM Developers Course
Page 16: Sage CRM Developers Course

Meta Data Definitions of Tables

Custom_DatabasesManages all the connections to remote databasesAll passwords encrypted using encryption algorithmsAll database connections are opened at the first CRM logonCustom_TablesBord_WebServiceTable enables extra objects to be exposed to the WSDLCustom_EditsEntryType controls how the system displays fieldsEntrySize controls how many characters can be entered on screen (can be changed, but must be <= column width)Colp_System may cause fields not to appear for selection. You can undo this, but be carefulCustom_ViewsThe whole system uses views to display dataViews should be maintained from within the CRM system, never from SQL ServerSQLLite relevant for SOLO only

Custom_Tablebord_tableid

1 Address 2 CaseProgress 3 Cases 4 Communication 5 Company 6 Email 7 Library 8 Marketing 9 Notes 10 Opportunity 11 OpportunityItem 12 OpportunityProgress 13 Person 14 Phone 15 Products 17 Team

Page 17: Sage CRM Developers Course

Basic Table Description

CREATE TABLE [dbo].[MyTable]([mytb_mytableid] [int] NOT NULL,[mytb_CreatedBy] [int] NULL,[mytb_CreatedDate] [datetime] NULL,[mytb_UpdatedBy] [int] NULL,[mytb_UpdatedDate] [datetime] NULL,[mytb_TimeStamp] [datetime] NULL,[mytb_Deleted] [int] NULL,[mytb_Secterr] [int] NULL,[mytb_Workflowid] [int] NULL,[mytb_Description] [nchar](30))

Create externally and then linkNot able to become full entityCreate table via interfaceAdvanced Customization Wizard. Entity Wizard

All Ids managed by CRMTabl_Secterr for primary entities only, enforces security on that entity.Security is discussed more later in the courseNew Table and Field definition will be in custom_tables and custom_edits

Page 18: Sage CRM Developers Course

Problems

Problems occur if developer introducesDatabase constraintsForeign key constraintsChecks Other changes such as identity columns.

Page 19: Sage CRM Developers Course

Holding Data in CRM

New Columns in TablesAdding columns to Entities, Company, Person, etcMarketing table for Company and Person

Rows as ColumnsKey Attribute Data– DD tables– Target List technique for SQL– Logs for use in screens

Data Sets– User_settings– Custom_sysparams

Page 20: Sage CRM Developers Course

Columns versus Datasets

Most data is held within a table within columnsE.g. User_userid, user_lastname, user_firstname.Some instances of using Datasets (or rows) to model attributesUser Preferences – Held in the usersettings table as a record set– E.g. To find a users timezone preference you would have to look in the usersettings table.Custom_sysparams– Hold system settings

Page 21: Sage CRM Developers Course

Datasets and Customizations

Can only use simple meta data definitions for screens where data is within a single row.Consider Company Summary Screen and – Companyboxlong– Addressboxshort– personboxshort

Require Advanced Customization for Screens and Lists for Phone/Email screensCustom_sysparamsUser_settingsKey Attribute Profiling

Examples of creating screens not based on single rows are covered in later part of the course

Page 22: Sage CRM Developers Course

Q&A

Page 23: 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 24: Sage CRM Developers Course