Customization Import failed. Error: OrganizationUI With Id =…… Does Not Exist or Failure: new_…: The requested record was not found or you do not have sufficient permissions to view it.


I was getting this error when i was trying to import customization for one of our custom entity from our development server to test server.

The way i resolved was

1) Opened the customization.xml file i was trying to import.

2) Search for the organization id which was mentioned in the event log as one not existing. (OrganizationUI With Id = 42467170-73ec-4b39-8eca-309ab0daece9 Does Not Exist)

3) I found the id in the  <FormXml id=”{42467170-73ec-4b39-8eca-309ab0daece9}”> tag.

4) I exported the customization for the same entity from my test server.

5) In the customization file(test server) i found out it had different id for FormXml.

6) Replace the id value for FormXml in the development server’s customization with id i found at the test server for the same entity.

7) Than i tried importing this newly modified file and it imported without giving any error.

Bye…

Upgrade or Using CRM 3 callouts in CRM 4


Hi,

These are the steps we followed for using crm 3.0 callouts in crm 4.0

In one case we upgraded our crm 3.0 to crm 4.0,

We had to put our crm 3.0 callouts in the following path

C:\Program Files\Microsoft CRM\Server\bin\assembly

We also had to put Microsoft.Crm.Platform.Callout.Base in the GAC.

Followed by an IISRESET

In second case, we had a fresh installation of  CRM 4.0.

We had to put our crm 3.0 callouts in the following path

C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly.

Followed by an IISRESET.

And things worked fine for us!!!

How to – Close an opportunity programmatically CRM


We can make use of following for closing the opportunity programmatically in CRM.

WinOpportunityRequest for closing an opportunity as won

//We create an instance of WinOpportunityRequest class as salesstage is Won.
WinOpportunityRequest woReq=new WinOpportunityRequest();
//WinOpportunityRequest takes 2 values: Opportunityclose and Status.
opportunityclose oc=new opportunityclose();
//Since Opportunityid is of type Lookup, we create an instance of the Lookup class. Lookup class has 2 attributes: Lookup.Value and Lookup.Type
Lookup lookup=new Lookup();
//We pass the GUID value of the opportunity to an instance of the Lookup class.
lookup.Value=entityContext.InstanceId;                                                                                          //We specify the type of the entity being passed.
lookup.type=EntityName.opportunity.ToString();
oc.opportunityid=lookup;
oc.actualend=actualclosedate(CrmDateTime variable);
oc.actualrevenue=new_estimatedrevenue(CrmMoney variable);
woReq.OpportunityClose=oc;

//The Status parameter corresponds to Status Reason in the Microsoft CRM application. If you pass -1 for this parameter, the platform sets the status to the appropriate value for the Microsoft CRM application.
woReq.Status=-1;
//The WinOpportunityRequest is sent to the platform using the Execute method. The platform will run the request and send back an instance of the Response class message.
WinOpportunityResponse woRes=(WinOpportunityResponse)service.Execute(woReq);


LoseOpportunityRequest for closing opportunity on lost and dropped
LoseOpportunityRequest loReq=new LoseOpportunityRequest();
//LoseOpportunityRequest takes 2 values: Opportunityclose and Status.
opportunityclose oc=new opportunityclose();
//Since Opportunityid is of type Lookup, we create an instance of the Lookup class. Lookup class has 2 attributes: Lookup.Value and Lookup.Type
Lookup lookup=new Lookup();
//We pass the GUID value of the opportunity to an instance of the Lookup class.
lookup.Value=entityContext.InstanceId;
//We specify the type of the entity being passed.
lookup.type=EntityName.opportunity.ToString();
oc.opportunityid=lookup;
oc.actualend=actualclosedate;
oc.actualrevenue=new_estimatedrevenue;
loReq.OpportunityClose=oc;
//The Status parameter corresponds to Status Reason in the Microsoft CRM application. If you pass -1 for this parameter, the platform sets the status to the appropriate value for the Microsoft CRM application.
loReq.Status=-1;
//The LoseOpportunityRequest is sent to the platform using the Execute method. The platform will run the request and send back an instance of the Response class message.
LoseOpportunityResponse loRes=(LoseOpportunityResponse)service.Execute(loReq);

Bye

Creating and Sending email in CRM using SendEmaiRequest


We can use the following code for creating and sending an email in CRM

/// <summary>
/// Creating and Sending mail in CRM
/// </summary>
/// <param name=”crmService”>an instance of crmService  (CrmService for CRM 3.0)</param>
/// <param name=”members”>ArrayList containing guids of the members</param>
/// <param name=”msg”>The message body</param>
/// <param name=”ownerID”>Owner of the record</param>
/// <param name=”userID”>User under whose context the callout or plugin is running </param>

private void SendMailToMembers(ICrmService crmService, ArrayList members, String msg, String ownerID, String userID)
{

// create an email
email emailCreate = new email();
emailCreate.subject = “MySubject”;
emailCreate.description = msg;

//specify the owner for the mail
emailCreate.ownerid = new Owner();
emailCreate.ownerid.type = EntityName.systemuser.ToString();
emailCreate.ownerid.Value = new Guid(ownerID);

//create an activityparty array holding all the guids specified in the members array list
activityparty[] ap = new activityparty[members.Count];
// creating as many activity party as the no of users or members in a team
int i = 0;
foreach (String memberID in members)
{
ap[i] = new activityparty();
ap[i].partyid = new Lookup();
ap[i].partyid.type = EntityName.systemuser.ToString();
ap[i].partyid.Value = new Guid(memberID);
i++;
}

// specify to part of the email
emailCreate.to = ap;

// specify the from part of the email
activityparty from = new activityparty();
from.partyid = new Lookup();
from.partyid.type = EntityName.systemuser.ToString();
from.partyid.Value = new Guid(userID);
emailCreate.from = new activityparty[] { from };

// finally create the email and get the guid of the email
Guid emailId = crmService.Create(emailCreate);

// FOR CRM 3.0
// Specify the system user who is sending the message.
//crmService.CallerIdValue = new CallerId();
//crmService.CallerIdValue.CallerGuid = new Guid(userID);
//

// Create an SendEmailRequest object
SendEmailRequest req = new SendEmailRequest();
req.EmailId = emailId;
req.TrackingToken = “”;
req.IssueSend = true;

// Finally Send the email message.
SendEmailResponse res = (SendEmailResponse)crmService.Execute(req);
}

Bye

PreEntity and PostEntity Images in CRM 4.0


Hi ,

When writing callouts for CRM 3.0, we were provided with PreEntityImageXml and PostEntityImageXml as a parameter to methds being overrided by us.

We could specify the fields for the same in the callout.config as prevalue and postvalue tag.

But the things have changed a bit in CRM 4.0.

Here we have to implement the Execute method found in the interface IPlugin.

public void Execute(IPluginExecutionContext context)

Here first we will register our assembly using Plugin Registration Tool

Than we will register a new step and specify the message against which we want to run our plugin.

After this comes the step where we will Register  new image.

In Register New Image dialog box

We can specify Pre Image and Post Image depending upon pre or post event. (Only for post event we can have both pre and post image)

Parameters -Here we can either specify certain fields or can select all attributes.

Entity Alias – Give a name to our image which we will refer in our code. (eg. say we gave LeadImage)

Now to access these values within our plugin we need  to do the following:-

Cast it into a DynamicEntity
DynamicEntity preLead = (DynamicEntity)context.PreEntityImages[“LeadImage”];
DynamicEntity postLead = (DynamicEntity)context.PostEntityImages[“LeadImage”];

For getting the id of the entity ( unlike crm 3.0 we don;t have entity context over here )

Key keyLeadId = (Key)postLead.Properties[“leadid”];
string leadId = keyLeadId.Value.ToString();

For lookup field use this line of code

Lookup lkpLobPre = (Lookup)preLead.Properties[“new_linesofbusinessid”];
strPreLobGuid = lkpLobPre.Value.ToString();
Lookup lkpLobPost = (Lookup)postLead.Properties[“new_linesofbusinessid”];
strPostLobGuid = lkpLobPost .Value.ToString();

For owner field

Owner ownerLead = (Owner)postLead.Properties[“ownerid”];
strPostOwnerGuid = ownerLead.Value.ToString();

For money field

CrmMoney estimatedvalue = (CrmMoney)postLead[“new_expectedrevenue”];
strExpectedRevenue = estimatedvalue.Value.ToString();

For string field

String geoName = (String)postLead[“new_geographyidname”];

For picklist field

Picklist leadqualitycode = (Picklist)postLead[“leadqualitycode”];
strRating = leadqualitycode.name;

Bye

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