Export (0) Print
Expand All
Expand Minimize

GrantAccess Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Works for all deployment typesWorks online only

Grants a security principal (user or team) access to the specified entity instance.

The relevant classes are specified in the following table.

TypeClass
RequestGrantAccessRequest
ResponseGrantAccessResponse
TargetTargetOwned Class
EntitySee below.

The following table shows the entities and target classes for this message.

EntityTarget Class
accountTargetOwnedAccount
annotationTargetOwnedannotation
appointmentTargetOwnedAppointment
asyncoperationTargetOwnedAsyncOperation
campaignTargetOwnedCampaign
campaignactivityTargetOwnedCampaignActivity
campaignresponseTargetOwnedCampaignResponse
contactTargetOwnedContact
contractTargetOwnedContract
customeropportunityroleTargetOwnedCustomerOpportunityRole
customerrelationshipTargetOwnedCustomerRelationship
duplicateruleTargetOwnedDuplicateRule
DynamicEntityTargetOwnedDynamic
emailTargetOwnedEmail
faxTargetOwnedFax
incidentTargetOwnedIncident
incidentresolutionTargetCreateIncidentResolution
invoiceTargetOwnedInvoice
leadTargetOwnedLead
letterTargetOwnedLetter
listTargetOwnedList
mailmergetemplateTargetOwnedMailMergeTemplate
opportunityTargetOwnedOpportunity
opportunitycloseTargetOwnedOpportunityClose
ordercloseTargetOwnedOrderClose
phonecallTargetOwnedPhoneCall
quoteTargetOwnedQuote
quotecloseTargetOwnedQuoteClose
reportTargetOwnedReport
salesorderTargetOwnedSalesOrder
serviceappointmentTargetOwnedServiceAppointment
taskTargetOwnedTask
templateTargetOwnedTemplate
User owned custom entityTargetOwnedX where X is the name of the entity
userqueryTargetOwnedUserQuery
workflowTargetOwnedWorkflow

Remarks

To use this message, pass an instance of the GrantAccessRequest class as the request parameter in the Execute method.

This action applies to all child instances of the target entity instance. For all child instances, if the caller does not have share privileges for those entity types, or share rights to the instances, the child instances are not shared. As a result, the owner of the instance, or a user who shares the instance with share rights, automatically has share rights to all child instances of the target entity instance. In this case, only the lack of privileges for a particular entity type prevents the child instances from being shared.

See Cascading Rules for a description of how actions on a parent instance affect child instances.

To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see GrantAccess Privileges.

Example

The following code example shows how to use the GrantAccess message.

[C#]
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the SecurityPrincipal Object
SecurityPrincipal principal = new SecurityPrincipal();
principal.Type = SecurityPrincipalType.User;

// PrincipalId is the Guid of the user to whom access is being granted
principal.PrincipalId = new Guid("7B222F98-F48A-4AED-9D09-77A19CB6EE82");

// Create the PrincipalAccess Object
PrincipalAccess principalAccess = new PrincipalAccess();

// Set the PrincipalAccess Object's Properties
principalAccess.Principal = principal;

// Gives the principal access to read
principalAccess.AccessMask = AccessRights.ReadAccess;

// Create the Target Object for the Request
TargetOwnedAccount target = new TargetOwnedAccount();

// EntityId is the Guid of the account access is being granted to
target.EntityId = new Guid("6A92D3AE-A9C9-4E44-9FA6-F3D5643753C1");

// Create the Request Object
GrantAccessRequest grant = new GrantAccessRequest();

// Set the Request Object's properties
grant.PrincipalAccess = principalAccess;
grant.Target = target;

// Execute the Request
GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grant);
[Visual Basic .NET]
' Set up the CRM service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create the SecurityPrincipal Object
Dim principal As New SecurityPrincipal()
principal.Type = SecurityPrincipalType.User

' PrincipalId is the Guid of the user to whom access is being granted
principal.PrincipalId = New Guid("7B222F98-F48A-4AED-9D09-77A19CB6EE82");

' Create the PrincipalAccess Object
Dim principalAccess As New PrincipalAccess()

' Set the PrincipalAccess Object's Properties
principalAccess.Principal = principal

' Gives the principal access to read
principalAccess.AccessMask = AccessRights.ReadAccess

' Create the Target Object for the Request
Dim target As New TargetOwnedAccount()

' EntityId is the Guid of the account access is being granted to
target.EntityId = New Guid("6A92D3AE-A9C9-4E44-9FA6-F3D5643753C1");

' Create the Request Object
Dim grant As New GrantAccessRequest()

' Set the Request Object's properties
grant.PrincipalAccess = principalAccess
grant.Target = target

' Execute the Request
Dim granted As GrantAccessResponse = CType(service.Execute(grant), GrantAccessResponse)

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft