CRM 2011 : Using OrganizationServiceClient to Update owner, Share/ Unshare record (OrganizationRequest, Grant Access, Revoke Access)

I was trying to execute all kinds of operation using pure WCF call to CRM 2011, without adding any xrm dll or early bound class. To make the whole piece of code dynamic and free of any externsal source, it can be achieved by adding the WCF service end point(.svc end point) and using two methods provided by this call (“OrganizationServiceClient” and “OrganizationRequest”). In this section, I will try to update owner of newly created Account record and shaer/unshare that record to a system user.

Update owner :

OrganizationRequest _objIR = new OrganizationRequest(){ RequestName = “Assign”, Parameters = newParameterCollection() };

_objIR.Parameters.Add(newKeyValuePair<string, object>( “Assignee”, newEntityReference() { Id = newGuid(“system user id of new owner”), LogicalName = “systemuser”} ));

_objIR.Parameters.Add(new KeyValuePair<string, object>( “Target”, newEntityReference() { Id = “guid of account record”, LogicalName = “account”} ));

OrganizationServiceClient_object.Execute(_objIR1);

Share record:

OrganizationRequest _objIR1 = newOrganizationRequest() { Parameters = newParameterCollection(), RequestName = “GrantAccess”};

_objIR1.Parameters.Add(newKeyValuePair<string, object>( “Target”, newEntityReference(){ Id = “guid of account record”, LogicalName = “account”} ) );

_objIR1.Parameters.Add(newKeyValuePair<string, object>( “PrincipalAccess”newPrincipalAccess()

{ Principal =new EntityReference() { Id = newGuid(“system user id”), LogicalName = “systemuser”} , AccessMask = AccessRights.AppendAccess | AccessRights.AppendToAccess | AccessRights.CreateAccess | AccessRights.DeleteAccess |AccessRights.WriteAccess }  ) );

 OrganizationServiceClient_object.Execute(_objIR1);

 

UnShare record:

OrganizationRequest _objUnShare = new OrganizationRequest() { Parameters = newParameterCollection(), RequestName = “RevokeAccess”};

_objUnShare.Parameters.Add(newKeyValuePair<string, object>(“Target”, newEntityReference() { Id = _accCreated, LogicalName = “account”}));

_objUnShare.Parameters.Add(newKeyValuePair<string, object>(“Revokee”, newEntityReference(){Id =

 new Guid(“system user id of the revokee”),LogicalName =“systemuser” } ) );

OrganizationServiceClient_objectt.Execute(_objUnShare);

 Note: you may face the serialization error while trying to perform these operations, since in the current WCF call there is no specific methods to serialize objects of “EntityReference” and “PrincipalAccess”(since they are specific to CRM only). One way to solve is to add an defination for these methods that will serialize their objects.

This can be achieved by adding beloe lines to “public partialclass OrganizationRequest” in Reference.cs class file of the WFC service file :: 

[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(PrincipalAccess))]

There should be some way to solve this issue without adding these two definations. I will post as soon as I find it.

regards

joon

Advertisements

About Joon
quite ordinary man

3 Responses to CRM 2011 : Using OrganizationServiceClient to Update owner, Share/ Unshare record (OrganizationRequest, Grant Access, Revoke Access)

  1. Prime Cheats says:

    Very energetic article, I liked that bit.
    Will there be a part 2?

  2. Danny Ong says:

    awesome article! Thanks!

  3. Destroyer says:

    Since the admin of this site is working, no uncertainty very shortly it will be well-known, due to
    its quality contents.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: