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
 
Function
Description
openEntityForm
Opens an entity form
openWebResource
Opens an HTML web resource.

1. openEnityForm
Use to open an entity.

Syntax
Xrm.Utility.openEntityForm(name,id,parameters)

Examples:
Open a new account record
Xrm.Utility.openEntityForm("account");
Open an existing account record
Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");
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
Note
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");
newWindow.moveTo(0,0);
newWindow.resizeTo(800,600);

2. openWebResource

Opens an HTML web resource.

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

Examples:
1.     Open an HTML web resource named “new_webResource.htm”:
Xrm.Utility.openWebResource("new_webResource.htm");
2.     Open an HTML web resource including a single item of data for the data parameter”
Xrm.Utility.openWebResource("new_webResource.htm","dataItemValue");
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");
Xrm.Utility.openWebResource("new_webResource.htm",customParameters);

Note
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:
Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");
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();
_service.Update(sitemap);

Step 4: Publish the sitemap

Now you need to publish the sitemap.


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

Helpful links
http://msdn.microsoft.com/en-us/library/gg309259.aspx

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
where
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

Tuesday, June 26, 2012

CRMSvcUtil.exe parameter is incorrect

Today i have got a strange message while creating early bind class code even i have entered correct parameters in command line.
error: Parameter is incorrect
I have use following command
CrmSvcUtil.exe /url:https://myorg.crm.dynamics.com/XRMServices/2011/Organization.svc
    /out:GeneratedCode.cs /username:"myname@live.com" /password:"myp@ssword!" 
Which is correct.
Then i got a solution and decided to share with you
go to the below location
C:\Users\Mubasher(your username)
and delete the folder
LiveDeviceID

Run the above command again.
I hope it helps you. Please share your experience in comments.
For more help on CrmSvcUtil.exe Extension Usage and Command-Line Parameters please check the following link
http://msdn.microsoft.com/en-us/library/gg695820.aspx

Saturday, June 9, 2012

How to Display a Report in a Dashboard in Dynamics CRM 2011?

There are a lot of reasons to display a Report within a Dashboard. And i have decided to write my own blog for this purpose And take help from this blog. So today i am sharing the steps so you can do it on your project too.
1. Run the report you want to display in a Dashboard.
2. Press F11 Copy the URL that displays in address bar
3. Create a New Dashboard. Chose any layout that fits in your requirement
4. Insert an IFRAME in the Dashboard.








5.  Paste the above Url after making the following adjustments to it:
  • Remove “http://myservername/myorgname” . This will make your url relative.
  • Replace “?action=filter” with “?action=run”. This will bypass the first step before running the report where CRM asks for some parameters.
for instance, if the original url was:
http://crm-vm222/MyOrg222/crmreports/viewer/viewer.aspx?action=filter&helpID=My%20Report%20Name.rdl&id=%7bE70C6DCA-31FF-E011-807F-CCCC293AE41E%7d
..then, you should write:
/crmreports/viewer/viewer.aspx?action=run&helpID=My%20Report%20Name.rdl&id=%7bE70C6DCA-31FF-E011-807F-CCCC293AE41E%7d

6. Also, clear checkbox ‘Restrict cross-frame scripting’ . At least in my case I had to do that to make it work.



7. Use the buttons ‘Increase Width’ and ‘Increase Height’ so as to make the IFRAME fill the whole page of your Dashboard (or just the space it’s supposed to need).


8. Save & Close the Dashboard.
9. Publish the Dashboard.
10. Try It! :) . After publishing make some minor changes like size / layout depending upon your requirement.But our main pupose has been achieved which is displaying the report.
Hope it helps,