Unable to cast object of type ‘Microsoft.Crm.Sdk.Moniker’ to type ‘Microsoft.Crm.Sdk.DynamicEntity’


I was writing my first callout ( plugin) for CRM 4.0 when i recieved this error.

I realized that this was because of this line of code in my plugin

public void Execute(IPluginExecutionContext context)
{

DynamicEntity   entity = (DynamicEntity)context.InputParameters.Properties[“Target”];

……

For Create and Update message there was no problem.

Problem started coming when i registered the step for Assign message.

So modified the code as following

DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains(“Target”) &&
context.InputParameters.Properties[“Target”] is DynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties[“Target”];
}

For Assign Message used the following line of code

if (context.MessageName == “Assign”)
{
Moniker myMoniker = null;
if (context.InputParameters.Properties.Contains(“Target”) &&
context.InputParameters.Properties[“Target”] is Moniker)
{
// Obtain the target business entity from the input parmameters.
myMoniker = (Moniker)context.InputParameters.Properties[“Target”];
}

myMoniker.Name –> Gave the name of the entity

myMoniker.Id –> Gave the id of the entity

Bye

Retrieving Members of Team – CRM


Hi,

We can make use of the following function for retrieving the members of a particular team

It takes as parameter instance of a ICrmService(CRM 4.0) or CrmService (CRM 3.0) and the guid of the team and returns an arraylist of of all the members found in the team

public ArrayList GetMembersOfTeam(ICrmService service, String TeamID)
{
// We want the guid of the system users in the team
ColumnSet cols = new ColumnSet(new String[] { “systemuserid” });
// We need to make use of RetrieveMembersTeamRequest class for that
RetrieveMembersTeamRequest rmtRequest = new RetrieveMembersTeamRequest();
// Converting the string TeamID to guid
Guid headGuid = new Guid(TeamID);

rmtRequest.EntityId = headGuid;
rmtRequest.MemberColumnSet = cols;

RetrieveMembersTeamResponse retrieved = (RetrieveMembersTeamResponse)service.Execute(rmtRequest);

// using generic businessEntity list
List<BusinessEntity> sysResult = retrieved.BusinessEntityCollection.BusinessEntities;

// for CRM 3.0
// BusinessEntity[] sysResult = retrieved.BusinessEntityCollection.BusinessEntities;

ArrayList userGuid = new ArrayList();

foreach (BusinessEntity be in sysResult)
{
systemuser user = (systemuser)be;
userGuid.Add(user.systemuserid.Value.ToString());
}
return userGuid;
}

Bye

System.Net.WebException the request failed with HTTP status 401: Unauthorized.” Source=”System.Web.Services”


Hi,

I was gettng this error when trying to call the crm’s webservice from my asp.net page

The resolution for this is putting the following code in the web.conig

i.e. enable impersonation and deny anonymous access

<authentication mode=”Windows” />
<identity impersonate=”true”/>
<authorization>
<!–Deny all unauthenticated users–>
<deny users=”?”/>
</authorization
>

Bye

Only the owner of an object can revoke the owner’s access to that object


Hi,

We had written a callout for auto sharing and unsharing of opportunity’s record for postassign event.

On creation of the record we were auto sharing the record with the owner’s manager.

On change of the owner we are first unsharing the record with the owner’s manager and sharing it with new owner’s manager.

While doing this the error we are receiving  is  this

“Only the owner of an object can revoke the owner’s access to that object “

This error is  coming in this particular scenario

say we have a record shared with a particular user say A

now when we are trying to set the new owner as A what the code is trying to do is that,

it is trying to unshare the record with A  this is the point where we receiving this  error!!!

For e.g.

Lead record is owned by User A and is Shared with User A.

Now the Revoke code is running in context of User B and tries to run Revoke for User A who is the owner. We will get this error message.

Bye..

Microsoft Dynamics CRM 3.0 and Microsoft Dynamics CRM 4.0 differences


Multiple organizations can now be hosted and WSDL APIs are now unique per organization.

 

The metadata API service has been extended to retrieve language information.

 

Plug-ins (callouts) and workflow now use the same event framework, allowing for even more extensibility.

 

The SDK has been expanded to include offline access.

 

Now we can programmatically create, read, update and delete the metadata such as entities, attributes and relationship.

 

There are three services instead of two which we used to have in previous version

 

CrmService – http://<crmserver>/mscrmservices/2007/crmservice.asmx

MetadataService – http://<crmserver>/mscrmservices/2007/metadataservice.asmx

DiscoveryService – http://<crmserver>/mscrmservices/2007/ad/crmdiscoveryservice.asmx

 

Previously to write callout we had to reference the follwing assembly

 

Microsoft.Crm.Platform.Callout.Base.dll

 

Instead now we have to reference these assemblies

 

  • Micorsoft.Crm.Sdk.dll
  • Micorsoft.Crm.SdkTypeProxy.dll
  • Micorsoft.Crm.Outlook.Sdk.dll

 

 

Now we can to settings and can then select customizations there we have the option of

Download Web Service Description File.

 

There we can find wsdl files for both CrmService and MetadataService which we can download to our machine and can the simply add web reference to them.

 

 

Previously to access and use the CrmService following lines of code were enough

 

CrmService service=new CrmService();

service.Url=// url for the CrmService

service.Credentials=System.Net.CredentialCache.DefaultCredentials;

 

But now because of the multiple organization support we need to write the following lines of code to identify the organization for which we are writing our custom solution.

 

CrmAuthenticationToken token = new CrmAuthenticationToken();

token.AuthenticationType = 0;

            // 0- Active Directory

            // 1- Microsoft Dynamics CRM Live

            // 2- Internet-Facing deployment (IFD)

token.OrganizationName=“”;// name of the organization

 

CrmService service=new CrmService();

service .Url=// url for the CrmService            service.Credentials=System.Net.CredentialCache.DefaultCredentials;

service.CrmAuthenticationTokenValue = token;

 

 

We have to access the Metadataservice in the similar manner i.e. creating CrmAuthenticationToken and assigning it to CrmMetadataService’s CrmAuthenticationTokenValue.

 

In 3.0 version we could use Metadataservice to access metadata information about any specific entity however in the new version following things are possible

 

  • Creating a customentity.
  • Add or update an attribute for an entity.
  • Create or delete a relationship between two entities.
  • Add or remove an option from a picklist attribute and few others.

 

 

  // CrmDiscoveryService Web service can provide a list of organizations and their corresponding Web service

 // endpoints URL’s. We will use it to configure the CrmService and MetadataService Web service proxies.

           

  CrmDiscoveryService discService = new CrmDiscoveryService();

  discService.UseDefaultCredentials = true;

  discService.Url = http://localhost/MSCRMServices/2007/AD/CrmDiscoveryService.asmx&#8221;;

 

  // Retrieve the list of organization

RetrieveOrganizationsRequest orgRequest = new    RetrieveOrganizationsRequest();

RetrieveOrganizationsResponse orgResponse =(RetrieveOrganizationsResponse) discService.Execute(orgRequest);

 

// Loop through the list to locate the target organization

 

OrganizationDetail orgInfo = null;

foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)

{

if (orgDetail.OrganizationName == “OurOrganizationName”)

    {

          orgInfo = orgDetail;

          break;

    }

}

 

After obtaining the organization details, we can then access the CrmService and MetadataService Web Services to perform our business logic.

 

 

References :

Working with Microsoft Dynamics CRM 4.0 (Microsoft Press)

JavaScript and Microsoft Dynamics CRM


I was thinking that it would have been nice if some expert would have written some article or post about how to use JavaScript within CRM.

And today only i came to know about such an article , it is written by none other than MichaelHohne, the CRM guru, the creator of stunnware site( the most helpful site for Microsoft CRM Developer)

For different things we can do by making use of JavaScript in Microsoft Dynamics CRM,

Plzzzz check and bookmark this url

http://www.stunnware.com/crm2/topic.aspx?id=JS13

Bye