Tuesday, August 30, 2011

Cancel a Service Order Programatically using C#

There are times when we need to cancel a service order using out custom code. The following code helps us achieve that.


/// Active     -  0    => New - 1, Pending - 2
/// Submitted  -  1    => In Progress - 3
/// Canceled   -  2    => No Money - 4,
/// Fulfilled  -  3    => Complete - 100001, Partial - 100002
/// Invoiced   -  4    => Invoiced - 100003

           try
           {
               CancelSalesOrderRequest setstate = new CancelSalesOrderRequest
               {
                   RequestName = "CancelSalesOrder",
                   OrderClose = new OrderClose { SalesOrderId = new EntityReference("salesorder", OrderID)},
                   Status = new OptionSetValue(status),

               };

               CancelSalesOrderResponse setstateresponse = (CancelSalesOrderResponse)Service.Execute(setstate);
           }
           catch (Exception ex)
           {
               
           }


OrderID = Should be the sales order Guid that we should be cancelling.
Above the code are the statuses that we get for Status field.

Thursday, August 18, 2011

Continuous Integration

We have been working with this for a project that we are currently doing. This is a very good and cool feature to use. Helps deployments a lot too.
The following is a very good article written regarding this topic. I will post some more articles related to this topic. Enjoy..

http://nickhoggard.wordpress.com/2010/08/21/first-look-using-tfs2010-for-continuous-integration/

Wednesday, August 17, 2011

Working with solutions Programmatically

Sometimes we want to import/export solutions programmatically to a CRM server. We came across a situation like this recently.

We were greatly helped by the following article.

Tuesday, August 9, 2011

CRM 2011 Error Message “An error occurred when verifying security for the message.”

This is a very strange error that we got with the CRM server that we were working with. After getting this error we started researching and found some URL’s containing information regarding this.  The answer we finally got was very strange.

The reason for this is the server was in a different time zone and our development machines were in a different time zone. When we changed the development machine time zone and go the time equal to the server time, the error disappears and we were able to get the result. Very strange ha… one might be wondering whether CRM is not working with different time zones, but it is. I will be searching on this bit more just to find out why this is happening.

The URL that helped me is below.

http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/a113c062-3879-4a79-8236-ac60fdfbf2bc/



Further to this after searching we found out in the client machines didn't counter the day light saving  and once we started this to counter it we didn't even have to change the Time Zone. This issue is because server is trying to synchronize  the time and since the times are not getting correctly synched we are getting this generic message.


Refer the URL below.


http://blogs.microsoft.co.il/blogs/rdt/archive/2011/04/04/accessing-dynamics-crm-2011-organization-service-it-s-all-about-timing.aspx

ASP.Net App_Code folder classes

The Classes that is getting put to this folder is not getting accessed from outside this folder. You might be wondering why this happens. The answer is simple. It doesn't get compiled to the DLL in the bin. If you right click on the class and go to properties window you will be see an entry called "Build Action". This is set to content which causes the issue. If you change this dropdown value to compile then your issue would get solved. But please keep in mind there might be issues doing this also.

Wednesday, August 3, 2011

Creating Many to Many Records in CRM 2011(N:N) using C#


There is a bit of change in CRM 2011 than CRM 4. The code is below.


Microsoft.Xrm.Sdk.EntityReference Moniker1 = new Microsoft.Xrm.Sdk.EntityReference();
Moniker1.Id = ProductID;
Moniker1.Name = "product";//Entity Name
                   
 
// Code Create Moniker for second Entity: New_CustomEntity
Microsoft.Xrm.Sdk.EntityReference Moniker2 = new Microsoft.Xrm.Sdk.EntityReference();
Moniker2.Id = contactid;
Moniker2.Name = "contact";//Entity Name

AssociateManyToManyEntityRecords(Moniker1, Moniker2, “product_contact”);


public bool AssociateManyToManyEntityRecords(Microsoft.Xrm.Sdk.EntityReference moniker1, Microsoft.Xrm.Sdk.EntityReference moniker2, string strEntityRelationshipName)
        {
            try
            {
                // Create an AssociateEntities request.
//Namespace is Microsoft.Crm.Sdk.Messages
                AssociateEntitiesRequest request = new AssociateEntitiesRequest();
                // Set the ID of Moniker1 to the ID of the lead.
                request.Moniker1 = new EntityReference { Id = moniker1.Id, LogicalName = moniker1.Name };
                // Set the ID of Moniker2 to the ID of the contact.
                request.Moniker2 = new EntityReference { Id = moniker2.Id, LogicalName = moniker2.Name };
                // Set the relationship name to associate on.
                request.RelationshipName = strEntityRelationshipName;
               
                // Execute the request.
                this.Service.Execute(request);
 

                return true;
            }

Error Message could not load file or assembly 'FSharp.Core'

The complete error message that I got is this.

Could not load file or assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified

I got this error message when I was working with a workflow that was related to continue integration. After surfing the google I download the following tool and installed in my machine. After that I was able to work with the workflows again.

I was helped by the following article.

F Sharp downloading URL

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...