Entities and the Data Model (Part 1 of 2)

advertisement
Sage CRM Developers Course
Entities and the
Data Model (Part 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 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
Use of SQL in Blocks
Use of SQL in Interface
Building Views
Entities and the Security Model
Tips for Building views with Derived Fields
Use of SQL in Blocks,
Use of SQL in
Interface
Using SQL & CRM
CRM must use SQL for all its database actions.
Uses vendor specific SQL e.g.
Oracle SYSDATE
SQL Server GETDATE()
SQL Trace (SQL Profiler) allows developer to identify actual data
manipulation.
Views Utilized
Actual DML passed (c.f. Security Territories & mail merge –user info)
Developer will need to establish requirement to support Databases
within component
View Syntax Differences
List Blocks in ASP pages
var comp_companyid = CRM.GetContextInfo('company','comp_companyid');
var projectlist = CRM.GetBlock('list');
with (projectlist)
{
//Table project is a custom added table
//SelectSQL is property of CRM ListBlock object
SelectSQL = 'select * from project, opportunity where oppo_projectid =
proj_projectid '
SelectSQL += ' and proj_companyid =' + comp_companyid;
var proj_name = AddGridCol('proj_name');
var proj_userid = AddGridCol('proj_userid');
}
CRM.AddContent(projectlist.Execute());
Response.Write(CRM.GetPage());
# Codes
Code
Meaning
#U
Current User ID
#L
#T
#C
#D
#R
#O
#N
Escalation Rules Dashboard Blocks OrderQuotes
SQL
SQL
Configuration
P
Current User Logon Name P
Current System Date/Time P
P
Current User Team ID
Current User Team Name P
O
Recent List Info
O
Current Opportunity ID
Current Version
O
Order/Quote
P
P
P
P
P
P
O
O
P
O
O
P
O
O
P
P
Tab SQL clause
Provides simple control access to tabs
U: 4,5
– Only user with user_userid equal to 4 or 5 can use tab
C: 4,5 (user_primarychannelid)
– Only user in team 4 or 5 can use tab
Tab SQL clause
Where Clause only
E.g. in My CRM opportunities tab only appears for users with
opportunities assigned to them.
– exists (select * from opportunity where oppo_assigneduserid = user_userid)
Can reference either current user or entity in context NOT both
Groups –SQL feature
Full control over SQL statement.
Change automatic ‘and’ clauses
to ‘or’
Groups and their access via Key
Attributes allow Companies to be
grouped.
Entities and the
Security Model
Entity Relationships
Entity Concept used in:
Person_Link
Security
Workflow
Data Upload
Reporting & Groups
Coding
PeLi_PersonLinkId
I2
I1
FK1
PeLi_PersonId
PeLi_CompanyID
PeLi_Type
PeLi_CreatedBy
PeLi_CreatedDate
PeLi_UpdatedBy
PeLi_UpdatedDate
PeLi_TimeStamp
PeLi_Deleted
Pers_PersonId
Person
Pers_PersonId
I1
I1
– Context
– Entity & Table level scripts
I2
Entity Definition Contingent on
Context within CRM
Can define own Entities to be
managed by CRM
VIEWS govern entity/context
definition
I3
FK1
Pers_CompanyId
Pers_PrimaryAddressId
Pers_PrimaryUserId
Pers_Salutation
Pers_FirstName
Pers_LastName
Pers_MiddleName
Pers_Suffix
Pers_Gender
Pers_Title
Pers_TitleCode
Pers_Department
Pers_Status
Pers_Source
Pers_Territory
Pers_WebSite
Pers_MailRestriction
Pers_PhoneCountryCode
Pers_PhoneAreaCode
Pers_PhoneNumber
Pers_EmailAddress
Pers_FaxCountryCode
Pers_FaxAreaCode
Pers_FaxNumber
Pers_CreatedBy
Pers_CreatedDate
Pers_UpdatedBy
Pers_UpdatedDate
Pers_TimeStamp
Pers_Deleted
Pers_LibraryDir
Pers_SegmentID
Pers_ChannelID
Pers_UploadDate
pers_SecTerr
Pers_WorkflowId
TList_ListId
Email
I1
I2
FK1
Company
Emai_EmailId
Comp_CompanyId
Emai_CompanyID
Emai_PersonID
Emai_Type
Emai_EmailAddress
Emai_CreatedBy
Emai_CreatedDate
Emai_UpdatedBy
Emai_UpdatedDate
Emai_TimeStamp
Emai_Deleted
Emai_SegmentID
Emai_ChannelID
Pers_PersonId
Comp_PrimaryPersonId
Comp_PrimaryAddressId
Comp_PrimaryUserId
Comp_Name
Comp_Type
Comp_Status
Comp_Source
Comp_Territory
Comp_Revenue
Comp_Employees
Comp_Sector
Comp_IndCode
Comp_WebSite
Comp_MailRestriction
Comp_PhoneCountryCode
Comp_PhoneAreaCode
Comp_PhoneNumber
Comp_FaxCountryCode
Comp_FaxAreaCode
Comp_FaxNumber
Comp_EmailAddress
Comp_CreatedBy
Comp_CreatedDate
Comp_UpdatedBy
Comp_UpdatedDate
Comp_TimeStamp
Comp_Deleted
Comp_LibraryDir
Comp_SegmentID
Comp_ChannelID
Comp_SecTerr
Comp_WorkflowId
Comp_UploadDate
comp_SLAId
I1
Address
Addr_AddressId
I1
FK1
FK2
Addr_Address1
Addr_Address2
Addr_Address3
Addr_Address4
Addr_Address5
Addr_City
Addr_State
Addr_Country
Addr_PostCode
Addr_CreatedBy
Addr_CreatedDate
Addr_UpdatedBy
Addr_UpdatedDate
Addr_TimeStamp
Addr_Deleted
Addr_SegmentID
Addr_ChannelID
addr_uszipplusfour
Comp_CompanyId
Pers_PersonId
I2
I3
Phone
Phon_PhoneId
I1
I2
Address_Link
AdLi_AddressLinkId
I1
I2
I3
FK1
FK3
AdLi_AddressId
AdLi_CompanyID
AdLi_PersonID
AdLi_Type
AdLi_CreatedBy
AdLi_CreatedDate
AdLi_UpdatedBy
AdLi_UpdatedDate
AdLi_TimeStamp
AdLi_Deleted
Comp_CompanyId
Addr_AddressId
FK1
Phon_CompanyID
Phon_PersonID
Phon_Type
Phon_CountryCode
Phon_AreaCode
Phon_Number
Phon_CreatedBy
Phon_CreatedDate
Phon_UpdatedBy
Phon_UpdatedDate
Phon_TimeStamp
Phon_Deleted
Phon_SegmentID
Phon_ChannelID
Comp_CompanyId
Simple vs Complex
Entities Relationships
Consider
Lead
LeadProgress
PK
Leads & Company & Opportunity
Role of personlink table and
Person and Company
relationship
Related Companies and the
multipleentitylink table
Communications and Comm_link
FK1
PK
Lead_LeadProgressID
Lead_CreatedBy
Lead_CreatedDate
Lead_UpdatedBy
Lead_UpdatedDate
Lead_TimeStamp
Lead_Deleted
Lead_LeadID
Lead_AssignedUserID
Lead_ChannelID
Lead_Status
Lead_Stage
Lead_Priority
Lead_Details
Lead_ProgressNote
Lead_ReasonNotInterested
Lead_Source
Lead_Description
Lead_Secterr
lead_decisiontimeframe
lead_waveitemid
lead_opened
lead_rateddate
lead_rating
lead_SLADateUpdated
lead_Duration
I3
I4
I1
I5
I2
FK1
FK2
Lead_LeadID
Lead_CreatedBy
Lead_CreatedDate
Lead_UpdatedBy
Lead_UpdatedDate
Lead_TimeStamp
Lead_Deleted
Lead_PrimaryCompanyID
Lead_PrimaryPersonID
Lead_CompanyName
Lead_CompanyAddress1
Lead_CompanyAddress2
Lead_CompanyAddress3
Lead_CompanyAddress4
Lead_CompanyCity
Lead_CompanyState
Lead_CompanyCountry
Lead_CompanyPostCode
Lead_CompanyIndustry
Lead_CompanyRevenue
Lead_CompanyEmployees
Lead_PersonFirstName
Lead_PersonLastName
Lead_PersonPhoneCountryCode
Lead_PersonPhoneAreaCode
Lead_PersonPhoneNumber
Lead_PersonFaxCountryCode
Lead_PersonFaxAreaCode
Lead_PersonFaxNumber
Lead_PersonEMail
Lead_CompanyWebSite
Lead_PersonTitle
Lead_PersonSalutation
Lead_AssignedUserID
Lead_Source
Lead_Stage
Lead_Status
Lead_Description
Lead_Details
Lead_Rating
Lead_ChannelID
Lead_Opened
Lead_Closed
Lead_NotifyTime
Lead_OpportunityID
Lead_Priority
Lead_SecTerr
Lead_CompanyMatch
Lead_DataUpLoadID
Lead_UpLoadDate
Lead_WorkflowId
Lead_ReasonNotInterested
lead_MailRestriction
lead_Type
lead_Sector
lead_WaveItemID
lead_rateddate
lead_decisiontimeframe
lead_mainproductinterest
lead_personmiddlename
lead_addressuszipplusfour
Pers_PersonId
Comp_CompanyId
Person_link table
Example Intersection Table
Person_link
Address_link
Person and Company relationship
Direct foreign key relationship between
Parent Company and Child Person
E.g. pers_companyid
Direct Relationship used in most
views, exceptions
vListPerson
vUserContacts
vReportUserContacts
Person_Link table used in
Also Intersection Table used to allow peoplelist action called from
company tab.
recording of ‘role’ of person within
company.
Type of Person maintained via
Translations
Userid, Createdby,
Channelid, SecTerr
Cases
Communication
case_assigneduserid cmli_comm_userid
Company
Lead
Opportunity
Person
comp_primaryuserid lead_assigneduserid oppo_assigneduserid pers_primaryuserid
case_channelid
comm_channelid
comp_channelid
lead_channelid
oppo_channelid
pers_channelid
case_secterr
comm_secterr
comp_secterr
lead_secterr
oppo_secterr
pers_secterr
case_createdby
cmli_createdby
comp_createdby
lead_createdby
oppo_createdby
pers_createdby
Intersection tables do not have these columns.
person_link
comm_link
Multipleentitylink
Security is cumulative
User must have rights on all tables referenced in view before can access record.
E.g. to see communication for a company and person, then user must have rights
on communication, company and person.
Building Views, Tips
for Building views with
Derived Fields
Changing or Adding Views
Add & edit database views using
the CRM Interface.
Custom_views
Recommend creation of new
views not editing of existing
views where possible.
Typical views changed
Merge views
Reports
Target Lists
Mail Merge Views
Sage CRM v7.1sp2 onwards
Context
View
Company
vMailMergeCompany
Person
vMailMerge
Opportunity
vMailMergeOpportunity
Case
vMailMergeCase
Orders
vMailMergeOrders
vMailMergeChildrenOrders
Quotes
vMailMergeQuotes
vMailMergeChildrenQuotes
Lead
vListLead
Expressions in Views
Date Ranges
Calculations
Concatenations
SELECT DATEDIFF(day, oppo_opened, getdate()) AS oppo_days FROM opportunity
WHERE oppo_status = 'In Progress';
Example of Expression in View
The Case List "caselist" uses the view "vListCases".
CREATE VIEW vListCases AS SELECT RTRIM(ISNULL(Pers_FirstName, '')) + ' ' + RTRIM(ISNULL(Pers_LastName, '')) AS Pers_FullName,
CASE WHEN Case_Status <> 'closed' AND Case_SLACloseBY < GETDATE() THEN 'Red' WHEN Case_Status <> 'closed' AND
Case_SLAAmberCloseBy < GETDATE() THEN 'Amber' ELSE 'Green' END AS Case_Color, Pers_PersonId, Pers_CreatedBy, Cases.*,
Comp_Name, Comp_CompanyId, Comp_CreatedBy, Pers_SecTerr, Comp_secTerr, Pers_PrimaryUserId, Comp_PrimaryUserId,
Pers_ChannelId, Comp_ChannelId, Chan_ChannelId, Chan_Description, Comp_EmailAddress, Pers_EmailAddress FROM Cases LEFT
OUTER JOIN Person ON Pers_PersonId = Case_PrimaryPersonId LEFT OUTER JOIN Company ON Comp_CompanyId =
Case_PrimaryCompanyId LEFT OUTER JOIN Channel ON Comp_ChannelId = Chan_ChannelId WHERE Case_Deleted IS NULL
CASE statement
CASE WHEN Case_Status <> 'closed' AND Case_SLACloseBY < GETDATE() THEN 'Red' WHEN Case_Status <> 'closed' AND Case_SLAAmberCloseBy <
GETDATE() THEN 'Amber' ELSE 'Green' END AS Case_Color
which evaluates whether the green, amber or red colour should be used.
Case_Color
The column "case_color" DOES NOT exist in the database. It is an entirely derived
"alias".
In order for this derived column to look like it is part of CRM it must have meta data
to control its properties.
select * from custom_edits
where colp_colname = 'case_color‘
select * from custom_captions
where capt_family = 'colnames'
and capt_code = 'case_color'
SQL on external tables
May need to reference external database on same server:
Reporting
Graphing
Use fully qualified table names
select vusers.user_firstname,vusers.user_lastname, northwind..orders.* from vusers
left join northwind..orders on user_userid = employeeid;
Q&A
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)
Download