tag:blogger.com,1999:blog-16603854383708047042024-03-08T14:55:00.733-07:00My Dynamics CRM BlogTips and tricks for Dynamics CRM 4, 2011, 2013, 2015 / online from a Dynamics CRM ExpertAnonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-1660385438370804704.post-18550564054766044322016-03-07T14:14:00.001-07:002016-03-07T14:14:06.460-07:00CRM 2016 WEB API - Retrieve Specific Record<span style="background-color: white; color: #666666; font-family: "trebuchet ms" , "trebuchet" , sans-serif; font-size: 13px; line-height: 18.2px;">This is a helper function to retrieve and specific record in CRM 2016 using the WEB API</span><br />
<span style="background-color: white; color: #666666; font-family: "trebuchet ms" , "trebuchet" , sans-serif; font-size: 13px; line-height: 18.2px;"><br /></span>
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">function</span> RetrieveEntity2016(clientURL, entityId, entityType, query) {
<span style="color: #008800; font-weight: bold;">var</span> req <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> XMLHttpRequest();
req.open(<span style="background-color: #fff0f0;">'GET'</span>, clientURL <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">"/api/data/v8.0/"</span>; <span style="color: #333333;">+</span> entityType <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">"("</span> <span style="color: #333333;">+</span> entityId <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">")"</span> <span style="color: #333333;">+</span> query, <span style="color: #008800; font-weight: bold;">true</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"Accept"</span>, <span style="background-color: #fff0f0;">"application/json"</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"Content-type"</span>, <span style="background-color: #fff0f0;">"application/json; charset=utf-8"</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"OData-MaxVersion"</span>, <span style="background-color: #fff0f0;">"4.0"</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"OData-Version"</span>,<span style="background-color: #fff0f0;">"4.0"</span>);
req.onreadystatechange <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">function</span> () {
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #008800; font-weight: bold;">this</span>.readyState <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">4</span> <span style="color: #888888;">/* complete */</span>) {
req.onreadystatechange <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">null</span>;
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #008800; font-weight: bold;">this</span>.status <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">200</span>) {
<span style="color: #008800; font-weight: bold;">var</span> data <span style="color: #333333;">=</span> <span style="color: #007020;">window</span>.JSON.parse(<span style="color: #008800; font-weight: bold;">this</span>.response);
console.log(<span style="background-color: #fff0f0;">"Retrieved "</span> <span style="color: #333333;">+</span> entityType <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" with entity id "</span><span style="color: #333333;">+</span> data.accountid);
}
<span style="color: #008800; font-weight: bold;">else</span> {
<span style="color: #008800; font-weight: bold;">var</span> error <span style="color: #333333;">=</span> <span style="color: #007020;">window</span>.JSON.parse(<span style="color: #008800; font-weight: bold;">this</span>.response).error;
console.log(error.message);
}
}
};
req.send();
}
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-64550699040093656362016-03-07T13:48:00.001-07:002016-03-07T13:48:44.730-07:00CRM 2016 WEB API - Create record with JavascriptThis is a helper function to create records in CRM 2016 using the WEB API<br />
<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">function</span> CreateRecord2016(entity, entityName){
<span style="color: #008800; font-weight: bold;">try</span>{
<span style="color: #888888;">/* Example of entity : note, all fields in lowercase</span>
<span style="color: #888888;"> var CRMObject = new Object(); </span>
<span style="color: #888888;"> CRMObject.new_name = "test name"; </span>
<span style="color: #888888;"> CRMObject.new_customfieldname = "test"; </span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">var</span> req <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> XMLHttpRequest()
req.open(<span style="background-color: #fff0f0;">"POST"</span>,<span style="color: #007020;">encodeURI</span>(clientURL <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">"/api/data/v8.0/"</span> <span style="color: #333333;">+</span> entityName <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">"s"</span>), <span style="color: #008800; font-weight: bold;">true</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"Accept"</span>, <span style="background-color: #fff0f0;">"application/json"</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"Content-Type"</span>, <span style="background-color: #fff0f0;">"application/json; charset=utf-8"</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"OData-MaxVersion"</span>, <span style="background-color: #fff0f0;">"4.0"</span>);
req.setRequestHeader(<span style="background-color: #fff0f0;">"OData-Version"</span>, <span style="background-color: #fff0f0;">"4.0"</span>);
req.onreadystatechange <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">function</span> () {
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #008800; font-weight: bold;">this</span>.readyState <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">4</span> <span style="color: #888888;">/* complete */</span>) {
req.onreadystatechange <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">null</span>;
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #008800; font-weight: bold;">this</span>.status <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">204</span>) {
<span style="color: #008800; font-weight: bold;">var</span> createdRecordId <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">this</span>.getResponseHeader(<span style="background-color: #fff0f0;">"OData-EntityId"</span>);
result <span style="color: #333333;">=</span> createdRecordId;
}
<span style="color: #008800; font-weight: bold;">else</span> {
<span style="color: #008800; font-weight: bold;">var</span> error <span style="color: #333333;">=</span> JSON.parse(<span style="color: #008800; font-weight: bold;">this</span>.response).error;
<span style="color: #888888;">//console.log(error.message);</span>
result <span style="color: #333333;">=</span> error;
}
}
};
req.send(<span style="color: #007020;">window</span>.JSON.stringify(entity));
<span style="color: #888888;">//Asynchronous AJAX function to Create a CRM record using OData </span>
<span style="color: #008800; font-weight: bold;">return</span> result;
}<span style="color: #008800; font-weight: bold;">catch</span>(err){
showError(arguments.callee.toString().match(<span style="background-color: #fff0ff; color: black;">/function\s+([^\s\(]+)/</span>)[<span style="color: #0000dd; font-weight: bold;">1</span>], err.message);
}
}
<span style="color: #008800; font-weight: bold;">function</span> showError(functionName, errorMessage)
{
alert(functionName <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">": "</span> <span style="color: #333333;">+</span> errorMessage);
}
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com2tag:blogger.com,1999:blog-1660385438370804704.post-2679699459219394752015-09-08T10:55:00.001-07:002015-09-08T10:55:22.616-07:00Function to make the form read only and skip the fields you wantfunction formdisable() {<br />
var skipFields = ",new_fieldtoskip1name,new_fieldtoskip2name,";<br />
<br />
var allAttributes = Xrm.Page.data.entity.attributes.get();<br />
for (var i in allAttributes) {<br />
var myattribute = Xrm.Page.data.entity.attributes.get(allAttributes[i].getName());<br />
var myname = myattribute.getName();<br />
if (skipFields.indexOf("," + myname + ",") != -1) {<br />
continue;<br />
}<br />
<br />
try {<br />
Xrm.Page.getControl(myname).setDisabled(true);<br />
} catch (err) {}<br />
}<br />
}Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com3tag:blogger.com,1999:blog-1660385438370804704.post-17574079434901982932015-06-10T15:04:00.001-07:002015-06-10T15:04:03.181-07:00Retrieve Global Optionset list of values with C#<pre style="line-height: 16.25px;">This is a method that you can use to retrieve a Global Optionset list of values with C#, it works for CRM 2011, 2013 and 2015.</pre>
<pre style="color: #333333; line-height: 16.25px;"><span style="color: #888888;">
</span></pre>
<pre style="color: #333333; line-height: 16.25px;"><span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Method to retrieve global optionset metadata values</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="_serviceProxy">CRM Service instance</param></span>
<span style="color: #888888;">/// <param name="_globalOptionSetName">Global Optionset name</param></span>
<span style="color: #888888;">/// <returns>Returns the global optionset metadata values</returns></span>
<span style="color: #008800; font-weight: bold;">private</span> OptionMetadata[] <span style="color: #0066bb; font-weight: bold;">GetGlobalOptionsetValues</span>(OrganizationServiceProxy _serviceProxy, <span style="color: #333399; font-weight: bold;">string</span> _globalOptionSetName)
{
OptionMetadata[] result = <span style="color: #008800; font-weight: bold;">null</span>;
<span style="color: #888888;">// Use the RetrieveOptionSetRequest message to retrieve </span>
<span style="color: #888888;">// a global option set by it's name.</span>
RetrieveOptionSetRequest retrieveOptionSetRequest = <span style="color: #008800; font-weight: bold;">new</span> RetrieveOptionSetRequest(){ Name = _globalOptionSetName };
<span style="color: #888888;">// Execute the request.</span>
RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)_serviceProxy.Execute(retrieveOptionSetRequest);
<span style="color: #888888;">// Access the retrieved OptionSetMetadata.</span>
OptionSetMetadata retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;
<span style="color: #888888;">// Get the current options list for the retrieved attribute.</span>
result = retrievedOptionSetMetadata.Options.ToArray();
<span style="color: #008800; font-weight: bold;">return</span> result;
} </pre>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-16392682907338998242015-06-09T13:23:00.003-07:002015-06-09T13:24:30.557-07:00UserHasTeam for CRM 2013 - Check if a user belongs to X team with JavascriptMethod to check if the user belongs to X team, looking by name:<br />
<br />
You can call it this way:<br />
<br />
if(UserhasTeam("Sales Managers")){<br />
// Do something<br />
}else{}<br />
<br />
<br />
function UserHasTeam(teamName) {<br />
///<summary><br />
/// Checks to see if the current user is a member of a team with the passed in name.<br />
///</summary><br />
///<param name="teamName" type="String"><br />
/// A String representing the name of the team to check if the user is a member of.<br />
///</param><br />
// build endpoint URL<br />
var serverUrl = Xrm.Page.context.getClientUrl();<br />
var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";<br />
var result = false;<br />
// query to get the teams that match the name<br />
oDataEndpointUrl += "TeamSet?$select=Name,TeamId&$filter=Name eq '" + teamName + "'";<br />
//var service = GetRequestObject();<br />
var service = new XMLHttpRequest();<br />
service.open("GET", oDataEndpointUrl, false);<br />
service.setRequestHeader("Accept", "application/json");<br />
service.setRequestHeader("Content-Type", "application/json;charset=utf-8");<br />
service.onreadystatechange = function() {<br />
if (service.readyState == 4) {<br />
if (service.status == 200) {<br />
debugger;<br />
var requestResults = JSON.parse(service.responseText).d;<br />
if (requestResults != null && requestResults.results.length > 0) {<br />
var teamCounter;<br />
// iterate through all of the matching teams, checking to see if the current user has a membership<br />
for (teamCounter = 0; teamCounter < requestResults.results.length; teamCounter++) {<br />
var team = requestResults.results[teamCounter];<br />
var teamId = team.TeamId;<br />
// get current user teams<br />
var currentUserTeams = getUserTeams(teamId);<br />
// Check whether current user teams matches the target team<br />
if (currentUserTeams != null) {<br />
for (var i = 0; i < currentUserTeams.length; i++) {<br />
var userTeam = currentUserTeams[i];<br />
// check to see if the team guid matches the user team membership id<br />
if (GuidsAreEqual(userTeam.TeamId, teamId)) {<br />
result = true;<br />
}<br />
}<br />
} else {<br />
result = false;<br />
}<br />
}<br />
} else {<br />
alert("Team with name '" + teamName + "' not found");<br />
result = false;<br />
}<br />
}<br />
}<br />
};<br />
service.send();<br />
<br />
return result;<br />
}<br />
<br />
function getUserTeams(teamToCheckId) {<br />
// gets the current users team membership<br />
var userId = Xrm.Page.context.getUserId().substr(1, 36);<br />
var serverUrl = Xrm.Page.context.getClientUrl();<br />
var result;<br />
<br />
var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";<br />
oDataEndpointUrl += "TeamMembershipSet?$filter=SystemUserId eq guid' " + userId + " ' and TeamId eq guid' " + teamToCheckId + " '";<br />
<br />
var service = new XMLHttpRequest();<br />
service.open("GET", oDataEndpointUrl, false);<br />
service.setRequestHeader("Accept", "application/json");<br />
service.setRequestHeader("Content-Type", "application/json;charset=utf-8");<br />
service.onreadystatechange = function() {<br />
if (service.readyState == 4) {<br />
if (service.status == 200) {<br />
// get user teams<br />
debugger;<br />
var requestResults = JSON.parse(service.responseText).d;<br />
if (requestResults != null && requestResults.results.length > 0) {<br />
result = requestResults.results;<br />
}<br />
}<br />
}<br />
}<br />
service.send();<br />
return result;<br />
}<br />
<br />
function GuidsAreEqual(guid1, guid2) {<br />
// compares two guids<br />
var isEqual = false;<br />
if (guid1 == null || guid2 == null) {<br />
isEqual = false;<br />
} else {<br />
isEqual = (guid1.replace(/[{}]/g, "").toLowerCase() == guid2.replace(/[{}]/g, "").toLowerCase());<br />
}<br />
return isEqual;<br />
}<br />
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-40565638063826852722015-06-09T13:11:00.002-07:002015-06-09T13:11:44.622-07:00RetrieveMultiple - Retrieve more than 5000 records with C#This method uses the RetrieveMultiple SDK Method and loops between all the Pages in order to avoid the 5000 records limitation.<br />
<br />
<pre style="background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: 'Courier New'; font-size: 13.3332996368408px; line-height: 20.7999992370605px; overflow-x: auto; overflow-y: hidden; padding: 0px; word-wrap: normal;"><span class="comment2" style="color: grey;">///</span><span class="comment" style="color: green;"> </span><span class="comment2" style="color: grey;"><summary></span><span class="comment" style="color: green;"></span>
<span class="comment2" style="color: grey;">///</span><span class="comment" style="color: green;"> Method used to return more than 5000 records at the same time</span>
<span class="comment2" style="color: grey;">///</span><span class="comment" style="color: green;"> </span><span class="comment2" style="color: grey;"></summary></span><span class="comment" style="color: green;"></span>
<span class="comment2" style="color: grey;">///</span><span class="comment" style="color: green;"> </span><span class="comment2" style="color: grey;"><param name="service"></span><span class="comment" style="color: green;">Organization service instance</span><span class="comment" style="color: green;"></span><span class="comment2" style="color: grey;"></param></span><span class="comment" style="color: green;"></span>
<span class="comment2" style="color: grey;">///</span><span class="comment" style="color: green;"> </span><span class="comment2" style="color: grey;"><param name="query"></span><span class="comment" style="color: green;">Query</span><span class="comment" style="color: green;"></span><span class="comment2" style="color: grey;"></param></span><span class="comment" style="color: green;"></span>
<span class="comment2" style="color: grey;">///</span><span class="comment" style="color: green;"> </span><span class="comment2" style="color: grey;"><returns></span><span class="comment" style="color: green;">All entities that matches the query</span><span class="comment" style="color: green;"></span><span class="comment2" style="color: grey;"></returns></span><span class="comment" style="color: green;"></span>
<span class="keyword" style="color: blue;">private</span> <span class="type" style="color: #2b91af;">List</span> < <span class="type" style="color: #2b91af;">Entity</span> > RetrieveMultiple(<span class="type" style="color: #2b91af;">OrganizationServiceProxy</span> service, <span class="type" style="color: #2b91af;">QueryExpression</span> query) {
<span class="type" style="color: #2b91af;">List</span> < <span class="type" style="color: #2b91af;">Entity</span> > result = <span class="keyword" style="color: blue;">new</span> <span class="type" style="color: #2b91af;">List</span> < <span class="type" style="color: #2b91af;">Entity</span> > ();
<span class="keyword" style="color: blue;">int</span> fetchCount = 5000;
<span class="keyword" style="color: blue;">int</span> pageNumber = 1;
query.PageInfo = <span class="keyword" style="color: blue;">new</span> <span class="type" style="color: #2b91af;">PagingInfo</span>();
query.PageInfo.Count = fetchCount;
query.PageInfo.PageNumber = pageNumber;
query.PageInfo.PagingCookie = <span class="keyword" style="color: blue;">null</span>;
<span class="keyword" style="color: blue;">while</span> (<span class="keyword" style="color: blue;">true</span>) {
<span class="type" style="color: #2b91af;">EntityCollection</span> collections = service.RetrieveMultiple(query);
<span class="keyword" style="color: blue;">if</span> (collections.Entities.Count > 0) {
result.AddRange(collections.Entities);
}
<span class="keyword" style="color: blue;">if</span> (collections.MoreRecords) {
query.PageInfo.PageNumber++;
query.PageInfo.PagingCookie = collections.PagingCookie;
} <span class="keyword" style="color: blue;">else</span> {
<span class="keyword" style="color: blue;">break</span>;
}
}
<span class="keyword" style="color: blue;">return</span> result;
}</pre>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com1tag:blogger.com,1999:blog-1660385438370804704.post-497528673654295982015-06-09T13:01:00.000-07:002015-06-09T13:01:17.198-07:00CRM 2013 - Unable to run any report<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-family: Arial, sans-serif;">Next time you are creating/editing security roles in CRM 2013 make
sure you add the privilege to<span class="apple-converted-space"> </span></span><b><span style="color: red; font-family: "Arial",sans-serif;">READ Currency</span></b><span class="apple-converted-space"><span style="font-family: Arial, sans-serif;"> </span></span><span style="font-family: Arial, sans-serif;">entity.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-family: Arial, sans-serif;"> I was fighting with this
issue, the users were unable to run any report under a new security role, after
testing privileges one by one, I noticed that the security role needs to have
the </span><b><span style="background: white; color: red; font-family: "Arial",sans-serif;">prvReadTransactionCurrency set
to Organization level</span></b><span style="background: white; color: red; font-family: "Arial",sans-serif;">,<span class="apple-converted-space"> </span></span><span style="background: white; font-family: Arial, sans-serif;">this will
allow the users to run any report (retrieving the data will depend on other
privileges).</span><span style="font-family: Arial, sans-serif;"><o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<br />
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Arial, sans-serif;">I will add pictures later...<o:p></o:p></span></div>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-83043268865120702342012-12-10T10:22:00.004-07:002012-12-10T11:47:51.838-07:00CRM 2011, Authenticate With No Help<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<br />
<pre style="overflow: auto; padding: 5px; word-break: break-all; word-wrap: break-word;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Since Office 365 authentication appeared, I had some troubles to authenticate from C# to CRM, (On premise, Online), but a few days ago, I found this helper that allows you to connect to any type of CRM environment, (On premise, Online with windows live id, or Online with office 365), enjoy :).</span></pre>
<pre style="overflow: auto; padding: 5px; word-break: break-all; word-wrap: break-word;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System;
<span style="color: blue;">using</span> System.ServiceModel;
<span style="color: blue;">using</span> System.ServiceModel.Description;
<span style="color: blue;">using</span> System.Reflection;
<span style="color: green;">// These namespaces are found in the Microsoft.Xrm.Sdk.dll assembly</span>
<span style="color: green;">// located in the SDK\bin folder of the SDK download.</span>
<span style="color: blue;">using</span> Microsoft.Xrm.Sdk;
<span style="color: blue;">using</span> Microsoft.Xrm.Sdk.Query;
<span style="color: blue;">using</span> Microsoft.Xrm.Sdk.Client;
<span style="color: blue;">using</span> Microsoft.Xrm.Sdk.Discovery;
<span style="color: blue;">using</span> Microsoft.Crm.Sdk.Messages;
<span style="color: blue;">namespace</span> Microsoft.Crm.Sdk.Samples
{
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> Demonstrate how to do basic authentication using IServiceManagement and SecurityTokenResponse.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: blue;">class</span> AuthenticateWithNoHelp
{
<span style="color: blue;">#region</span> Class Level Members
<span style="color: green;">// To get discovery service address and organization unique name, </span>
<span style="color: green;">// Sign in to your CRM org and click Settings, Customization, Developer Resources.</span>
<span style="color: green;">// On Developer Resource page, find the discovery service address under Service Endpoints and organization unique name under Your Organization Information.</span>
<span style="color: blue;">private</span> String _discoveryServiceAddress = <span style="color: #a31515;">"https://disco.crm.dynamics.com/XRMServices/2011/Discovery.svc"</span>;
<span style="color: blue;">private</span> String _organizationUniqueName = <span style="color: #a31515;">"crmue"</span>;
<span style="color: green;">// Provide your user name and password.</span>
<span style="color: blue;">private</span> String _userName = <span style="color: #a31515;">"sdk@crmue.onmicrosoft.com"</span>;
<span style="color: blue;">private</span> String _password = <span style="color: #a31515;">"ITG2install!"</span>;
<span style="color: green;">// Provide domain name for the On-Premises org.</span>
<span style="color: blue;">private</span> String _domain = <span style="color: #a31515;">"mydomain"</span>;
<span style="color: blue;">#endregion</span> Class Level Members
<span style="color: blue;">#region</span> How To Sample Code
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> </span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: blue;">public</span> <span style="color: blue;">void</span> Run()
{
IServiceManagement<IDiscoveryService> serviceManagement =
ServiceConfigurationFactory.CreateManagement<IDiscoveryService>(
<span style="color: blue;">new</span> Uri(_discoveryServiceAddress));
AuthenticationProviderType endpointType = serviceManagement.AuthenticationType;
<span style="color: green;">// Set the credentials.</span>
AuthenticationCredentials authCredentials = GetCredentials(endpointType);
String organizationUri = String.Empty;
<span style="color: green;">// Get the discovery service proxy.</span>
<span style="color: blue;">using</span> (DiscoveryServiceProxy discoveryProxy =
GetProxy<IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials))
{
<span style="color: green;">// Obtain organization information from the Discovery service. </span>
<span style="color: blue;">if</span> (discoveryProxy != <span style="color: blue;">null</span>)
{
<span style="color: green;">// Obtain information about the organizations that the system user belongs to.</span>
OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
<span style="color: green;">// Obtains the Web address (Uri) of the target organization.</span>
organizationUri = FindOrganization(_organizationUniqueName,
orgs.ToArray()).Endpoints[EndpointType.OrganizationService];
}
}
<span style="color: blue;">if</span> (!String.IsNullOrWhiteSpace(organizationUri))
{
IServiceManagement<IOrganizationService> orgServiceManagement =
ServiceConfigurationFactory.CreateManagement<IOrganizationService>(
<span style="color: blue;">new</span> Uri(organizationUri));
<span style="color: green;">// Set the credentials.</span>
AuthenticationCredentials credentials = GetCredentials(endpointType);
<span style="color: green;">// Get the organization service proxy.</span>
<span style="color: blue;">using</span> (OrganizationServiceProxy organizationProxy =
GetProxy<IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials))
{
<span style="color: green;">// This statement is required to enable early-bound type support.</span>
organizationProxy.EnableProxyTypes();
<span style="color: green;">// Now make an SDK call with the organization service proxy.</span>
<span style="color: green;">// Display information about the logged on user.</span>
Guid userid = ((WhoAmIResponse)organizationProxy.Execute(
<span style="color: blue;">new</span> WhoAmIRequest())).UserId;
SystemUser systemUser = organizationProxy.Retrieve(<span style="color: #a31515;">"systemuser"</span>, userid,
<span style="color: blue;">new</span> ColumnSet(<span style="color: blue;">new</span> <span style="color: blue;">string</span>[] { <span style="color: #a31515;">"firstname"</span>, <span style="color: #a31515;">"lastname"</span> })).ToEntity<SystemUser>();
Console.WriteLine(<span style="color: #a31515;">"Logged on user is {0} {1}."</span>,
systemUser.FirstName, systemUser.LastName);
}
}
}
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> Obtain the AuthenticationCredentials based on AuthenticationProviderType.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="endpointType"></span><span style="color: green;">An AuthenticationProviderType of the CRM environment.</param></span>
<span style="color: grey;">///</span> <span style="color: grey;"><returns></span><span style="color: green;">Get filled credentials.</returns></span>
<span style="color: blue;">private</span> AuthenticationCredentials GetCredentials(AuthenticationProviderType endpointType)
{
AuthenticationCredentials authCredentials = <span style="color: blue;">new</span> AuthenticationCredentials();
<span style="color: blue;">switch</span> (endpointType)
{
<span style="color: blue;">case</span> AuthenticationProviderType.ActiveDirectory:
authCredentials.ClientCredentials.Windows.ClientCredential =
<span style="color: blue;">new</span> System.Net.NetworkCredential(_userName,
_password,
_domain);
<span style="color: blue;">break</span>;
<span style="color: blue;">case</span> AuthenticationProviderType.LiveId:
authCredentials.ClientCredentials.UserName.UserName = _userName;
authCredentials.ClientCredentials.UserName.Password = _password;
authCredentials.SupportingCredentials = <span style="color: blue;">new</span> AuthenticationCredentials();
authCredentials.SupportingCredentials.ClientCredentials =
Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
<span style="color: blue;">break</span>;
<span style="color: blue;">default</span>: <span style="color: green;">// For Federated and OnlineFederated environments. </span>
authCredentials.ClientCredentials.UserName.UserName = _userName;
authCredentials.ClientCredentials.UserName.Password = _password;
<span style="color: green;">// For OnlineFederated single-sign on, you could just use current UserPrincipalName instead of passing user name and password.</span>
<span style="color: green;">// authCredentials.UserPrincipalName = UserPrincipal.Current.UserPrincipalName; //Windows/Kerberos</span>
<span style="color: blue;">break</span>;
}
<span style="color: blue;">return</span> authCredentials;
}
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> Discovers the organizations that the calling user belongs to.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="service"></span><span style="color: green;">A Discovery service proxy instance.</param></span>
<span style="color: grey;">///</span> <span style="color: grey;"><returns></span><span style="color: green;">Array containing detailed information on each organization that </span>
<span style="color: grey;">///</span><span style="color: green;"> the user belongs to.</returns></span>
<span style="color: blue;">public</span> OrganizationDetailCollection DiscoverOrganizations(
IDiscoveryService service)
{
<span style="color: blue;">if</span> (service == <span style="color: blue;">null</span>) <span style="color: blue;">throw</span> <span style="color: blue;">new</span> ArgumentNullException(<span style="color: #a31515;">"service"</span>);
RetrieveOrganizationsRequest orgRequest = <span style="color: blue;">new</span> RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse orgResponse =
(RetrieveOrganizationsResponse)service.Execute(orgRequest);
<span style="color: blue;">return</span> orgResponse.Details;
}
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> Finds a specific organization detail in the array of organization details</span>
<span style="color: grey;">///</span><span style="color: green;"> returned from the Discovery service.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="orgUniqueName"></span><span style="color: green;">The unique name of the organization to find.</param></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="orgDetails"></span><span style="color: green;">Array of organization detail object returned from the discovery service.</param></span>
<span style="color: grey;">///</span> <span style="color: grey;"><returns></span><span style="color: green;">Organization details or null if the organization was not found.</returns></span>
<span style="color: grey;">///</span> <span style="color: grey;"><seealso cref="DiscoveryOrganizations"/></span>
<span style="color: blue;">public</span> OrganizationDetail FindOrganization(<span style="color: blue;">string</span> orgUniqueName,
OrganizationDetail[] orgDetails)
{
<span style="color: blue;">if</span> (String.IsNullOrWhiteSpace(orgUniqueName))
<span style="color: blue;">throw</span> <span style="color: blue;">new</span> ArgumentNullException(<span style="color: #a31515;">"orgUniqueName"</span>);
<span style="color: blue;">if</span> (orgDetails == <span style="color: blue;">null</span>)
<span style="color: blue;">throw</span> <span style="color: blue;">new</span> ArgumentNullException(<span style="color: #a31515;">"orgDetails"</span>);
OrganizationDetail orgDetail = <span style="color: blue;">null</span>;
<span style="color: blue;">foreach</span> (OrganizationDetail detail <span style="color: blue;">in</span> orgDetails)
{
<span style="color: blue;">if</span> (String.Compare(detail.UniqueName, orgUniqueName,
StringComparison.InvariantCultureIgnoreCase) == 0)
{
orgDetail = detail;
<span style="color: blue;">break</span>;
}
}
<span style="color: blue;">return</span> orgDetail;
}
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> Generic method to obtain discovery/organization service proxy instance.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: grey;">///</span> <span style="color: grey;"><typeparam name="TService"></span>
<span style="color: grey;">///</span><span style="color: green;"> Set IDiscoveryService or IOrganizationService type to request respective service proxy instance.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></typeparam></span>
<span style="color: grey;">///</span> <span style="color: grey;"><typeparam name="TProxy"></span>
<span style="color: grey;">///</span><span style="color: green;"> Set the return type to either DiscoveryServiceProxy or OrganizationServiceProxy type based on TService type.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></typeparam></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="serviceManagement"></span><span style="color: green;">An instance of IServiceManagement</param></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="authCredentials"></span><span style="color: green;">The user's Microsoft Dynamics CRM logon credentials.</param></span>
<span style="color: grey;">///</span> <span style="color: grey;"><returns></span><span style="color: grey;"></returns></span>
<span style="color: blue;">private</span> TProxy GetProxy<TService, TProxy>(
IServiceManagement<TService> serviceManagement,
AuthenticationCredentials authCredentials)
<span style="color: blue;">where</span> TService : <span style="color: blue;">class</span>
<span style="color: blue;">where</span> TProxy : ServiceProxy<TService>
{
Type classType = <span style="color: blue;">typeof</span>(TProxy);
<span style="color: blue;">if</span> (serviceManagement.AuthenticationType !=
AuthenticationProviderType.ActiveDirectory)
{
AuthenticationCredentials tokenCredentials =
serviceManagement.Authenticate(authCredentials);
<span style="color: green;">// Obtain discovery/organization service proxy for Federated, LiveId and OnlineFederated environments. </span>
<span style="color: green;">// Instantiate a new class of type using the 2 parameter constructor of type IServiceManagement and SecurityTokenResponse.</span>
<span style="color: blue;">return</span> (TProxy)classType
.GetConstructor(<span style="color: blue;">new</span> Type[] { <span style="color: blue;">typeof</span>(IServiceManagement<TService>), <span style="color: blue;">typeof</span>(SecurityTokenResponse) })
.Invoke(<span style="color: blue;">new</span> <span style="color: blue;">object</span>[] { serviceManagement, tokenCredentials.SecurityTokenResponse });
}
<span style="color: green;">// Obtain discovery/organization service proxy for ActiveDirectory environment.</span>
<span style="color: green;">// Instantiate a new class of type using the 2 parameter constructor of type IServiceManagement and ClientCredentials.</span>
<span style="color: blue;">return</span> (TProxy)classType
.GetConstructor(<span style="color: blue;">new</span> Type[] { <span style="color: blue;">typeof</span>(IServiceManagement<TService>), <span style="color: blue;">typeof</span>(ClientCredentials) })
.Invoke(<span style="color: blue;">new</span> <span style="color: blue;">object</span>[] { serviceManagement, authCredentials.ClientCredentials });
}
<span style="color: blue;">#endregion</span> How To Sample Code
<span style="color: blue;">#region</span> Main method
<span style="color: grey;">///</span> <span style="color: grey;"><summary></span>
<span style="color: grey;">///</span><span style="color: green;"> Standard Main() method used by most SDK samples.</span>
<span style="color: grey;">///</span> <span style="color: grey;"></summary></span>
<span style="color: grey;">///</span> <span style="color: grey;"><param name="args"></span><span style="color: grey;"></param></span>
<span style="color: blue;">static</span> <span style="color: blue;">public</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)
{
<span style="color: blue;">try</span>
{
AuthenticateWithNoHelp app = <span style="color: blue;">new</span> AuthenticateWithNoHelp();
app.Run();
}
<span style="color: blue;">catch</span> (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
{
Console.WriteLine(<span style="color: #a31515;">"The application terminated with an error."</span>);
Console.WriteLine(<span style="color: #a31515;">"Timestamp: {0}"</span>, ex.Detail.Timestamp);
Console.WriteLine(<span style="color: #a31515;">"Code: {0}"</span>, ex.Detail.ErrorCode);
Console.WriteLine(<span style="color: #a31515;">"Message: {0}"</span>, ex.Detail.Message);
Console.WriteLine(<span style="color: #a31515;">"Trace: {0}"</span>, ex.Detail.TraceText);
Console.WriteLine(<span style="color: #a31515;">"Inner Fault: {0}"</span>,
<span style="color: blue;">null</span> == ex.Detail.InnerFault ? <span style="color: #a31515;">"Has Inner Fault"</span> : <span style="color: #a31515;">"No Inner Fault"</span>);
}
<span style="color: blue;">catch</span> (System.TimeoutException ex)
{
Console.WriteLine(<span style="color: #a31515;">"The application terminated with an error."</span>);
Console.WriteLine(<span style="color: #a31515;">"Message: {0}"</span>, ex.Message);
Console.WriteLine(<span style="color: #a31515;">"Stack Trace: {0}"</span>, ex.StackTrace);
Console.WriteLine(<span style="color: #a31515;">"Inner Fault: {0}"</span>,
<span style="color: blue;">null</span> == ex.InnerException.Message ? <span style="color: #a31515;">"Has Inner Fault"</span> : <span style="color: #a31515;">"No Inner Fault"</span>);
}
<span style="color: blue;">catch</span> (System.Exception ex)
{
Console.WriteLine(<span style="color: #a31515;">"The application terminated with an error."</span>);
Console.WriteLine(ex.Message);
<span style="color: green;">// Display the details of the inner exception.</span>
<span style="color: blue;">if</span> (ex.InnerException != <span style="color: blue;">null</span>)
{
Console.WriteLine(ex.InnerException.Message);
FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException
<span style="color: blue;">as</span> FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>;
<span style="color: blue;">if</span> (fe != <span style="color: blue;">null</span>)
{
Console.WriteLine(<span style="color: #a31515;">"Timestamp: {0}"</span>, fe.Detail.Timestamp);
Console.WriteLine(<span style="color: #a31515;">"Code: {0}"</span>, fe.Detail.ErrorCode);
Console.WriteLine(<span style="color: #a31515;">"Message: {0}"</span>, fe.Detail.Message);
Console.WriteLine(<span style="color: #a31515;">"Trace: {0}"</span>, fe.Detail.TraceText);
Console.WriteLine(<span style="color: #a31515;">"Inner Fault: {0}"</span>,
<span style="color: blue;">null</span> == fe.Detail.InnerFault ? <span style="color: #a31515;">"Has Inner Fault"</span> : <span style="color: #a31515;">"No Inner Fault"</span>);
}
}
}
<span style="color: green;">// Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException,</span>
<span style="color: green;">// SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException.</span>
<span style="color: blue;">finally</span>
{
Console.WriteLine(<span style="color: #a31515;">"Press <Enter> to exit."</span>);
Console.ReadLine();
}
}
<span style="color: blue;">#endregion</span> Main method
}
}</span></pre>
<pre style="overflow: auto; padding: 5px; word-break: break-all; word-wrap: break-word;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">
</span></pre>
<pre style="overflow: auto; padding: 5px; word-break: break-all; word-wrap: break-word;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">You can find the original post <a href="http://msdn.microsoft.com/en-us/library/hh675404.aspx" target="_blank">here</a>.</span></pre>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com1tag:blogger.com,1999:blog-1660385438370804704.post-86507271055418673852012-11-06T11:58:00.006-07:002012-11-06T11:58:45.768-07:00Xrm.Utility <span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Well, I was not aware of this new object created by Microsoft, since Microsoft Dynamics CRM 2011 Update Rollup 8. (<a href="http://msdn.microsoft.com/en-us/library/jj602956.aspx">http://msdn.microsoft.com/en-us/library/jj602956.aspx</a>)</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">It has 2 function (both open a new browser window) called:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>- <a href="http://msdn.microsoft.com/en-us/library/jj602956.aspx#BKMK_OpenEntityForm" style="background-color: white; line-height: 18px; text-decoration: none;">openEntityForm</a> </b></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: x-small;"> </span>Xrm.Utility.openEntityForm(name,id,parameters) </span><br />
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /><b>Examples:</b></span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Open a new account record</b><br />Xrm.Utility.openEntityForm("account");</span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Open an existing account record</b><br />Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");<br /><br /><b>Open a new account record with a specific form and setting default values</b><br />var parameters = {};<br />parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";<br />parameters["name"] = "Test";<br />parameters["telephone1"] = "(425) 555-1234";<br />Xrm.Utility.openEntityForm("account", null, parameters);</span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Open a new contact record, move it to the top left corner of the screen, and set the size of the window</b> </span></blockquote>
<blockquote class="tr_bq">
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Note</b>You cannot use window object methods such as moveTo or resizeTo in scripts that will run in Microsoft Dynamics CRM for Microsoft Office Outlook.</span></blockquote>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> var newWindow = Xrm.Utility.openEntityForm("contact");<br />newWindow.moveTo(0,0);<br />newWindow.resizeTo(800,600);</span></blockquote>
<pre style="overflow: auto; padding: 5px; word-break: break-all; word-wrap: break-word;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">- <a href="http://msdn.microsoft.com/en-us/library/jj602956.aspx#BKMK_OpenWebResource" style="background-color: white; line-height: 18px; text-decoration: none;">openWebResource</a></span></b></pre>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)<br /></span><blockquote class="tr_bq">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Examples:</span></b></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Open an HTML web resource named </b>“new_webResource.htm”:Xrm.Utility.openWebResource("new_webResource.htm");</span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Open an HTML web resource including a single item of data for the data </b>parameter”Xrm.Utility.openWebResource("new_webResource.htm","dataItemValue");</span></blockquote>
<blockquote class="tr_bq">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Open an HTML web resource passing multiple values through the data parameter</span></b></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">var<b> </b>customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value");
Xrm.Utility.openWebResource("new_webResource.htm",customParameters); </span><blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Note</b>These values have to be extracted from the value of the data parameter in the HTML web resource. For more information, see <a href="http://msdn.microsoft.com/en-us/library/gg327945.aspx">Sample: Pass Multiple Values to a Web Resource Through the Data Parameter</a>.</span></blockquote>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Open an HTML web resource with the parameters expected by HTML web resources:</span></b></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");</span></blockquote>
<br /><br /><br /><br />Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-12325812289984060752012-10-31T10:49:00.001-07:002012-10-31T10:52:16.787-07:00CRM 2011 Recurring workflows - Running only one instance at the same timeMaybe some of you already read the post of how to implement a recurring workflow in Dynamics CRM 2011, I have read it from <a href="http://crmbusiness.wordpress.com/2011/05/24/crm-2011-how-to-schedule-recurring-workflows-in-crm-2011/">http://crmbusiness.wordpress.com/2011/05/24/crm-2011-how-to-schedule-recurring-workflows-in-crm-2011/</a> , the article is copied below.<br />
<br />
When I implemented this approach with a client, I had the next problem, The user was clicking on a ribbon button and that button was calling a JScript code that performed a call to a workflow using something similar to this: (<a href="http://andreaswijayablog.blogspot.com/2011/07/crm-2011-custom-button-on-custom-entity.html">http://andreaswijayablog.blogspot.com/2011/07/crm-2011-custom-button-on-custom-entity.html</a>)<br />
<br />
function callworkfow(id) {<br />
try {<br />
var guid;<br />
<br />
if (id == null) {<br />
guid = Xrm.Page.data.entity.getId();<br />
}<br />
else<br />
guid = id;<br />
<br />
// assign workflow guid<br />
var WorkflowId = "89BA3166-948E-4B12-8A55-4BE01DEDAB0B";<br />
<br />
var xml = "" +<br />
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +<br />
"<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\">" +<br />
Xrm.Page.context.getAuthenticationHeader() +<br />
"<soap:Body>" +<br />
"<execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +<br />
"<request xsi:type=\"ExecuteWorkflowRequest\">" +<br />
"<entityid>" + guid + "</EntityId>" +<br />
"<workflowid>" + WorkflowId + "</WorkflowId>" + //WorkflowId = guid of the workflow<br />
"</Request>" +<br />
"</Execute>" +<br />
"</soap:Body>" +<br />
"</soap:Envelope>";<br />
<br />
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");<br />
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);<br />
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");<br />
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");<br />
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);<br />
xmlHttpRequest.send(xml);<br />
<br />
var resultXml = xmlHttpRequest.responseXML;<br />
<br />
if (id == null)<br />
alert("Success");<br />
return (resultXml.xml);<br />
}<br />
catch (e) {<br />
alert("Failed to Execute");<br />
}<br />
}<br />
<br />
<br />
But, the problem here was that I needed to have only one instance of the workflow running at the same time, and the way it was implemented was creating a new instance of the workflow everytime the button was clicked, and as far as I know the CRM webservice does not have a way to retrieve Async Operations in case I need to be sure that any instance of the workflow was running before calling it, and neither the Plugins can be attached to Async Operations, so.. (If you already followed the tutorial from <a href="http://crmbusiness.wordpress.com/2011/05/24/crm-2011-how-to-schedule-recurring-workflows-in-crm-2011/">http://crmbusiness.wordpress.com/2011/05/24/crm-2011-how-to-schedule-recurring-workflows-in-crm-2011/</a> ), what I did to solve this problem is the next:<br />
<br />
<br />
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Change the workflow to run only as Child and on i.e. Appointments CREATION</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
--------------- USER ---------------------------------------------------------------------------------------------------------------------</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
<div>
- User clicks on the ribbon button, this will trigger the jscript code</div>
<div>
-------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div>
<br /></div>
<div>
--------------- JSCRIPT Code that will be called from the ribbon button------------------------------------------------</div>
<div>
- A jscript code searches for an appointment with subject "Only one workflow instance"</div>
<div>
- If the appointment is found, then do nothing.. (Because this means that the workflow is running already)</div>
<div>
- But if the appointment was not found, then CREATE an appointment with subject "Only one workflow instance", this will trigger the workflow.</div>
<div>
--------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div>
<br /></div>
<div>
-------------- WORKFLOW process -------------------------------------------------------------------------------------------------</div>
<div>
- Workflow starts</div>
<div>
- Do the work that needs to do..</div>
<div>
- Waits X time<br />
- Calls itself as again (This starts a new iteration)..</div>
<div>
- Workflow ends..</div>
<div>
--------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div>
<br /></div>
<div>
Also you can manage it using a plugin that triggers on the pre-create of i.e. Appointment.</div>
<div>
<br /></div>
<div>
I hope this helps!</div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-56981588241840836502012-09-04T08:26:00.000-07:002012-09-04T08:35:32.349-07:00Resco - Mobile CRM for Microsoft DynamicsIf you need to create mobile clients for Dynamics CRM, this is a complete solution to do that, is called Resco (<a href="http://www.resco.net/MobileCRM/">http://www.resco.net/MobileCRM/</a>).<br />
<br />
I am currently learning how to use it and to develop with its SDK, I will try to set a tutorial when I have learned it.<br />
<br />
<br />
<h3>
6 Key reasons why Resco Mobile CRM<br /> is the best solution in the market</h3>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
1 - Best features, always ahead of its competitors<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Mobility has been a key specialization for Resco since 1999.
We have worked with over 3,500 customers on their various mobile projects. We
are pioneers in this fast growing segment with the most experience in mobile
software from the consumer, developer and business perspective. This is the
main reason why Resco Mobile CRM is the best featured and technologically the
most rapidly evolving mobile CRM solution in the world.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
2 - Flexibility with frequent updates<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We listen to our partners and customers and realize most of
their suggestions in a reasonable timeframe. We usually release at least 4
major releases a year while all major releases bring significant new features.
In the meantime there are many updates and bug fixes based on the requests from
our customers, so they have a fix available in hours or days, instead of months
or years.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
3 - Platform independent solution with consistent UI<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
All competitive products have been developed for each mobile
platform separately. This resulted in multiple effort and the final applications
have huge differences in UI and supported features.<o:p></o:p></div>
<div class="MsoNormal">
Instead of that, Resco has used its platform independent
technology and only one developer team concentrating on CRM features instead of
dealing with platform specific issues. This resulted in significantly lower
development time needed, and the final application has the same UI and
supported features on all mobile platforms.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
4 - Assurance, the only SDK with source code<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Although our solution provides the same configurator tool
allowing configuration of the mobile app as all other competitors, Resco Mobile
CRM is the only solution which can provide its customers also with a platform
independent SDK. This .NET based developer platform allows unlimited
customizations of the mobile app and can be understood also as a customer
assurance. Thanks to this tool, our customers become independent from Resco,
the solution vendor, since they can make any changes or add new features
anytime they need them.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
5 - HTML5, the future technology is already available<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
While the others only speak, Resco acts. Resco Mobile CRM is
the only solution in its segment with real support of HTML5. Thanks to this
promising technology we allow our partners and customers to extend the UI and
functionality of Resco Mobile CRM by web technologies and designs.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
6 - Rapid deployment, no middleware<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Resco Mobile CRM doesn´t require any server component to be
installed on the CRM server, which significantly simplifies the solution
installation and setup. Instead of that, Microsoft Dynamics CRM Web Services
are used, which allow straightforward and secure integration of the mobile app
with the CRM server. Customers only download the mobile app and sync it with
their Microsoft Dynamics CRM. All customizations performed with Resco
configurator are downloaded during the synchronization and applied
automatically to the mobile app, which updates its UI and behavior immediately.</div>
<div class="MsoNormal">
<br /></div>
<br />
Have a nice day!Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-61497572046022820292012-03-29T19:14:00.000-07:002012-03-29T19:16:53.481-07:00First.. well second post<br />
Hello all!, well this is my first blog, I will try to post interesting things about Dynamics CRM, my apologies about my english, actually my native language is spanish but I will try to put everything in english.<br />
<br />
I hope this blog can help other developers just how others developers blogs have helped me in the bad times xD.<br />
<br />
Stay tunned!Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0tag:blogger.com,1999:blog-1660385438370804704.post-45235612511514988192012-03-29T16:28:00.001-07:002012-03-29T16:28:30.026-07:00CRM 2011 SDK 5.0.3 is now availableYup, the new version of the CRM 2011 SDK is available now for download at microsoft downloads site:<br />
<br />
<a href="http://www.microsoft.com/download/en/details.aspx?id=24004" target="_blank">here</a><br />
<br />
Happy coding!<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/13746874403582342771noreply@blogger.com0