CRM 2011 CS: Retrieve the schedule of a system user

/* Retrive The Schedule of Current User */

using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,

                                                    serverConfig.HomeRealmUri,

                                                    serverConfig.Credentials,

                                                    serverConfig.DeviceCredentials))

{

    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

 

                  

    // Get the current user's information.

    WhoAmIRequest userRequest = new WhoAmIRequest();

    WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);

 

    // Retrieve the schedule of the current user.                                           

    QueryScheduleRequest scheduleRequest = new QueryScheduleRequest

    {

        ResourceId = userResponse.UserId,

        Start = DateTime.Now,

        End = DateTime.Today.AddDays(7),

        TimeCodes = new TimeCode[] { TimeCode.Available }

    };

    QueryScheduleResponse scheduleResponse = (QueryScheduleResponse)_serviceProxy.Execute(scheduleRequest);

}

 

CRM 2011 CS: Retrieve the schedule of Multiple users

 

using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,

                                                    serverConfig.HomeRealmUri,

                                                    serverConfig.Credentials,

                                                    serverConfig.DeviceCredentials))

{

    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

 

    // Get the current user's information.

    WhoAmIRequest userRequest = new WhoAmIRequest();

    WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);

    Guid _currentUserId = userResponse.UserId;

 

    // Create another user

    Guid _otherUserId = new Guid("0a4252a0-7e70-11d0-a5d6-28db04c10000");

        

 

    // Retrieve the schedule of the current and the other user.                                           

    QueryMultipleSchedulesRequest scheduleRequest = new QueryMultipleSchedulesRequest();

    scheduleRequest.ResourceIds = new Guid[2];

    scheduleRequest.ResourceIds[0] = _currentUserId;

    scheduleRequest.ResourceIds[1] = _otherUserId;

    scheduleRequest.Start = DateTime.Now;

    scheduleRequest.End = DateTime.Today.AddDays(7);

    scheduleRequest.TimeCodes = new TimeCode[] { TimeCode.Available };

 

    QueryMultipleSchedulesResponse scheduleResponse = (QueryMultipleSchedulesResponse)_serviceProxy.Execute(scheduleRequest);

                   

}

 

CRM 2011 CS: Retrieve the schedule of Multiple users

using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,

                                                    serverConfig.HomeRealmUri,

                                                    serverConfig.Credentials,

                                                    serverConfig.DeviceCredentials))

{

    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

 

    // Get the current user's information.

    WhoAmIRequest userRequest = new WhoAmIRequest();

    WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);

    Guid _currentUserId = userResponse.UserId;

 

    // Create another user

    Guid _otherUserId = new Guid("0a4252a0-7e70-11d0-a5d6-28db04c10000");

        

 

    // Retrieve the schedule of the current and the other user.                                           

    QueryMultipleSchedulesRequest scheduleRequest = new QueryMultipleSchedulesRequest();

    scheduleRequest.ResourceIds = new Guid[2];

    scheduleRequest.ResourceIds[0] = _currentUserId;

    scheduleRequest.ResourceIds[1] = _otherUserId;

    scheduleRequest.Start = DateTime.Now;

    scheduleRequest.End = DateTime.Today.AddDays(7);

    scheduleRequest.TimeCodes = new TimeCode[] { TimeCode.Available };

 

    QueryMultipleSchedulesResponse scheduleResponse = (QueryMultipleSchedulesResponse)_serviceProxy.Execute(scheduleRequest);

                   

}

 

CRM 2011 PLUGIN: 5 syntax changes in Dynamics CRM 2011 plugins

5 syntax changes in Dynamics CRM 2011 plugins

There are number of changes between Dynamics CRM 2011 SDK and CRM 4 SDK. Let’s

take a look at what has changed between plugins.

 

1. The IPlugin now resides in Microsoft.Xrm.Sdk namespace instead of Microsoft.Crm.Sdk

public class ClassName : Microsoft.Crm.Sdk.IPlugin

public class ClassName : Microsoft.Xrm.Sdk.IPlugin

 

2. The Execute method signature of the IPlugin interface has changed, it now expects an IServiceProvider instead of the

public void Execute(IPluginExecutionContext context)

public void Execute(IServiceProvider serviceProvider)

 

3. To get a reference to the IPluginExecutionContext you now need to call the GetService method of the IServiceProvider

public void Execute(IPluginExecutionContext context)

Microsoft.Xrm.Sdk.IPluginExecutionContext context =(Microsoft.Xrm.Sdk.IPluginExecutionContext)

serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

 

4. ICrmService has been changed to IOrganizationService.

ICrmService sdk = context.CreateCrmService(true);

IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(y));

IOrganizationService sdk = factory.CreateOrganizationService(context.UserId);

 

5. DynamicEntity has been changed to Entity.

Properties property of DynamicEntity no longer exists

Getting and Setting values no longer use *Property classes,

eg: no more KeyProperty, StringProperty…etc, simply do int value = (int)entity[“schema_name”];

if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

CRM 2011 JS: SOAP Envelope By Example

/*

The following is the SOAP Request Example for new_entityname

*/

 

function SOAPReqbyExample() {

    var GUIDvalue = Xrm.Page.data.entity.getId();

    //var name = Xrm.Page.getattrib(

 

    if (GUIDvalue != null) {

 

        var varh = GUIDvalue;

    }

 

    var authenticationHeader = GenerateAuthenticationHeader();

 

    // Prepare the SOAP message.

    var xml = "<?xml version='1.0' encoding='utf-8'?>" +

"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +

" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +

authenticationHeader +

"<soap:Body>" +

"<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +

"<entity xsi:type='new_entityname'>" +

"<new_fieldname>" + varh + "</new_fieldname>" +

"</entity>" +

"</Create>" +

"</soap:Body>" +

"</soap:Envelope>";

    // Prepare the xmlHttpObject and send the request.

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");

    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

    xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Create");

    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    xHReq.setRequestHeader("Content-Length", xml.length);

    xHReq.send(xml);

    alert("Created");

    // Capture the result

    var resultXml = xHReq.responseXML;

 

    // Check for errors.

    var errorCount = resultXml.selectNodes('//error').length;

    if (errorCount != 0) {

        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;

        alert(msg);

    }

 

}

 

CRM 2011 Debug: How to Debug Plugins using Profiler

One can debug CRM plug ins without connecting to CRM server or without remote debugging.

 

Here are the steps as in how you can use Profiler for debugging plug ins:

   1>     Connect to CRM using plugin registration tool of March SDK 2012.

 

   2>      Click on Install Profiler

         

 

   3>     You will find a new node attached to registered plugins “Plugin Profiler”.

 

 




   4>     Select a plug-in step and click Profile to enable profiling.

 

 

 

5>     Then start your plugin from MSCRM i.e if your plugin is on update perform  update operation and download the error file.

6>     Then in Visual Studio attach to process “plugin registeration.exe”. Add the breakpoint  from where you would like to debug.

 

 

7>     Then click on Debug in plugin registration tool.

 

 

8>     In Profile location provide the path of the error log of the plugin.

 

9>     In Assembly location provide the dll of the plugin from which you got error.

 

10>     Then select the Plugin class from Plug-in. This drop down will contains all classes present in the dll.

 

11>     To start debugging just click on Start Plug-in Execution.

 

 

CRM 2011 JS: Insert FetchXml into subgrid chart's view using javascript

I went digging around on the net to find examples of this and did find serveral that got me in the right direction.  But I still seem to be missing something.  I think what I'm doing wrong is assigning the fetchxml to the subgrid rather than the chart's view in the subgrid.  Can anyone tell me how to fix this?  Thanks for all your help!

Here is the error message, not very helpful...

 

code:

function UpdateSubGrid() {

    var accountSales = document.getElementById("SalesSummary");

    if (accountSales.readyState != "complete") {

        setTimeout('UpdateSubGrid()', 1000);

        return;

    }

    var accID = Xrm.Page.data.entity.getId();

    alert(accID);

    var accountNum = Xrm.Page.getAttribute("jensen_accountnumber").getValue();

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>";

    fetchXml += " <entity name='account'>";

    fetchXml += " <attribute name='jensen_yeartodatesales' />";

    fetchXml += " <attribute name='jensen_yeartodateplan' />";

    fetchXml += " <attribute name='jensen_lastyearsales' />";

    fetchXml += " <attribute name='name' />";

    fetchXml += " <filter type='and'>";

    fetchXml += " <condition attribute='statecode' operator='eq' value='0' />";

    fetchXml += " <condition attribute='accountnumber' operator='eq' value='";

    fetchXml += accountNum;

    fetchXml += "' />";

    fetchXml += " </filter>";

    fetchXml += " <order attribute='name' descending='false' />";

    fetchXml += " </entity></fetch>";

    alert(fetchXml);

    accountSales.control.setParameter("fetchXml", fetchXml);

    accountSales.control.refresh();

}

 

 

Here is the Account form with the subgrid that has the chart in it, highlighted:

This chart us showing ALL accounts rather than being filter to the account I'm in.  The new fetchXml that I'm trying to assign it did not get set.

Posted by Cory Bonallo

 

CRM 2011: Steps to deploy custom aspx page

In CRM 2011 its not required to deploy it in ISV. We need to create a new web site. Firstly publish the solution to “/InetPub/wwwroot/<PublishFolderName>” or publish and copy the published files to the same path. Follow the below steps:

1. Goto IIS. Create a new website. Need not change the ApplicationPool. This should create a new ApplicationPool in the same name as the website. Specify a different port number which is not used by either CRM or any other websites. In Physical path give Published foler path in wwwroot(/InetPub/wwwroot/<PublishFolderName>).

2. Goto ApplicationPool and for the new ApplicationPool change the following properties:

  •  .Net FrameworkVersion – v4.0
  •  Managed Pipeline Mode – Classic (previously it will be Integrated)

3. Right click the ApplicationPool and Open advanced Settings. Change the Identity property to “Network Service”.Thats it:) done deploying..

You can check it by selecting ur aspx page and select Browse. Make a note of the url from the IE window.

 

CRM 2011: Attach OnClick event to all fields on the CRM Form and Passing querystring to silverlight web resource in the footer

 

/*

Attach a click event to all fields on the CRM 2011 form.

There is a silverlight page on the footer of the form. On click of any field i need to pass the schema name of the source field(which raised the event) to the silverlight page.

Using the Xrm properties we cannot get the control of a control in the footer.

Here I had to pass a dynamic parameter to the querystring of the silverlight web resource and the ‘setData’ method also cannot be used directly.

 

On load of the form I attached events to all label fields on the form.

For the web resource on the footer there is a property called ‘control’ which gave access to the ‘setData’ method.

Initially I dont want any data parameter to be passed. So in the web resource properties i passed an empty string as data parameter.

This allowed me to change the data parameter dynamically.

*/

 

function AttachAttributEvents()

{

    var attribs = Xrm.Page.data.entity.attributes.get();

    var attribName = "";

    for (var i in attribs)

    {

        attribName = attribs[i].getName();

        if (attribName != "")

        {

            document.getElementById(attribName + '_c').onclick = function ()

                { //Attach events to the label of each attribute

                    var Elt = window.event.srcElement.parentElement.id;

                    var EltName = Elt.substring(0, Elt.length - 2);

                    document.getElementById("WebResource_FieldInfo").control.setData(EltName); //Pass Data parameter to the web resource

                };

        }

    }

}

 

CRM 2011: Dynamically change sub-grid fetchXml - left navigation pane

In CRM 2011 account entity there are 2 left navigation links called Open Activities and Closed activities. When we select these, the sub-grid populates activites associated with the related contacts also. To filter them based on the regarding field we can use javascript to pass the fetchXml dynamically and change the view.

For this you need the IFrame id in which the grid gets loaded.

To get the IFrame control:

var frame = document.frames["areaActivitiesFrame"].frameElement;

Bind “onreadystatechange” event for the Iframe:

frame.onreadystatechange = function () {
if (event.srcElement.readyState == “complete”) {
BindGrid(“Open”, frame);
}
};

Get grid control and pass the fetchXml

function BindGrid(state, frame) {
var currentId = Xrm.Page.data.entity.getId();
var currentName = Xrm.Page.getAttribute(“name”).getValue();
var fetchXmlStr = getFetchXml(currentId, currentName, state);
fetchXmlStr += getFetchXml(null, null, state);
frame.contentWindow.document.getElementById(“AppGridFilterContainer”).style.display = “none”; //To hide filter
frame.contentWindow.document.getElementById(“newViewSelector”).innerText = state + “Activities:”; //Change the text
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers_SavedNewQuerySelector”).style.display = “none”;
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.setParameter(“fetchXmlForFilters”, fetchXmlStr);

frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.setParameter(“fetchXml”, fetchXmlStr);
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.refresh();

}

After getting the grid contol you can make any changes you want in the grid: changing the header text, hiding elements inside the grid…

Thanks.