Tuesday, July 31, 2012

Xrm.Utility Reference Microsoft Dynamics CRM 2011

New Xrm.Utility Functions in Update Rollup 8 for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online

Microsoft has introduce a new Xrm reference. These functions are available in every application page that supports script.
The functions are below
Opens an entity form
Opens an HTML web resource.

1. openEnityForm
Use to open an entity.


Open a new account record
Open an existing account record
Open a new account record with a specific form and setting default values
var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);
Open a new contact record, move it to the top left corner of the screen, and set the size of the window
You cannot use window object methods such as moveTo or resizeTo in scripts that will run in Microsoft Dynamics CRM for Microsoft Office Outlook.
var newWindow = Xrm.Utility.openEntityForm("contact");

2. openWebResource

Opens an HTML web resource.

Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)

1.     Open an HTML web resource named “new_webResource.htm”:
2.     Open an HTML web resource including a single item of data for the data parameter”
3.     Open an HTML web resource passing multiple values through the data parameter
var customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value");

These values have to be extracted from the value of the data parameter in the HTML web resource. For more information, see Sample: Pass Multiple Values to a Web Resource Through the Data Parameter.
Open an HTML web resource with the parameters expected by HTML web resources:
Open an HTML web resource, setting the height and width:
Xrm.Utility.openWebResource("new_webResource.htm", null, 300,300);

Thursday, July 26, 2012

Change the sitemap content programmatically in CRM 2011 (MSCRM)

We can change the content of the sitemap by using the CRM 2011 Webservice.
To accomplish this follow these steps

Step 1: Retrieve the sitemap

QueryExpression query = new QueryExpression();
query.EntityName = "sitemap";
query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true);

EntityCollection col = _service.RetrieveMultiple(query);

Entity sitemap = null;
if (col != null && col.Entities.Count > 0)
   sitemap  = col.Entities[0];

Step 2: Parse the sitemap entity to an XDocument object

string sitemapcontent = sitemap["sitemapxml"].ToString();
XDocument sitemapxml = XDocument.Parse(sitemapcontent);

You can now change the sitemap by modifying the sitemapxml object. After you made your changes, it's time to save these changes.

Step 3: Update the sitemap

sitemap["sitemapxml"] = sitemapxml.ToString();

Step 4: Publish the sitemap

Now you need to publish the sitemap.

PublishXmlRequest request = new PublishXmlRequest();
request.ParameterXml = "<importexportxml><sitemaps><sitemap></sitemap></sitemaps></importexportxml>";

Helpful links

Wednesday, July 25, 2012

how to edit expired contract in crm 2011

There is an unsupported method to do this you can do in database table ..contractbasetable and update the statecode and status code column to make it draft again..

(this is unsupported way also test the SQL Update on Dev/Test Environment before running on actual Live Environment)

update ContractBase
set StateCode = 0,
StatusCode = 1
ContractId = <<YOUR Contract ID>>

Run the above query and when you open your record in crm 2011 it will be draft update the contract and save it.

Thanks and regards

How to add more options in statuscode

Today i am going to tell you an unsupported option to customize statuscode attribute on appointment entity, there's one way you can do it for on-premise setup but because this is the unsupported modifications to the CRM system, I cannot guarantee for any issues due to that modification since I've never done that during any of my development and you may try it with your own risk.

First, you have to modify the statuscode attribute  of the Appointment entity to editable by running the following SQL script on your organization database.

UPDATE  MetadataSchema.Attribute SET Locked = 0
WHERE EntityId IN (SELECT Entityid FROM Entity WHERE logicalname
IN ('Appointment')) 
AND LogicalName = 'statuscode'

Then, open the statuscode attribute of the Appointment entity and add more options under Completed and Canceled status.

Retrieve a lookup field value in a Silverlight page as a WebResource in CRM 2011

To retrieve the values  of  a lookup field  or any other field in a  silverlight page, we need to  follow  two steps  i.e
1. Design the  silverlight application  to  retrieve the lookup field value.
And create  a web resource of type silverlight and upload the .xap file.
2. Create  a  webresource in the form customization area and pass the  field name whose value is needed in the silverlight page as  a parameter in the "custom parameter" area and point  to the web resource created in  the step 1.

We  need to  modify the  Application_startup method to captture the parameter  passed from the CRM controls,
Now  in  the Mainpage.xaml.cs we will get  a hold on  CRM object and retrieve the  value of the parameter that  we have passed as below,

dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");

var fieldName = Application.Current.Resources["InitParm_data"];

// for getting primary contact lookup field

var numAttr1 = xrm.Page.data.entity.attributes.get(fieldName).getValue()[0].id;

In the  same  way  we  can retrieve  different other fields.

we can also set the crm field values from within the  silverlight application  as  below,

dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
var numAttr = xrm.Page.data.entity.attributes.get("ser_noofusers");//ser_noofusers is  a custom field numAttr.setValue(Math.Round(slider1.Value, 0));

I hope it helps some one