DateTime fields in CRM 2015


Hi,

We recently had a requirement wherein we were working with DateTime fields in a Plugin. It was related to Time Zone.

These articles were of extreme help.

http://develop1.net/public/post/Dynamics-CRM-DateTimes-the-last-word.aspx

http://inogic.com/blog/2015/06/handling-datetime-fields-in-microsoft-dynamics-crm-update-1/

http://ttidbit.blogspot.com/2013/01/crm-timezone-codes.html

Sample Code to use LocalTimeFromUtcTimeRequest


var currentUserSettings = organizationProxy.RetrieveMultiple(
new QueryExpression("usersettings")
{
ColumnSet = new ColumnSet("timezonecode"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.EqualUserId)
}
}
}).Entities[0];

var timeZoneCode = currentUserSettings.Attributes["timezonecode"].ToString();

DateTime time1 = DateTime.UtcNow;

LocalTimeFromUtcTimeRequest convert = new LocalTimeFromUtcTimeRequest();
convert.UtcTime = time1.ToUniversalTime();
convert.TimeZoneCode = Convert.ToInt32(timeZoneCode);
LocalTimeFromUtcTimeResponse response = (LocalTimeFromUtcTimeResponse)organizationProxy.Execute(convert);
MessageBox.Show(response.LocalTime.ToString());

 

The interesting part was that our plugin was running under the context of System account, so to get the logged in user from UI, we added an additional field and populated the value of time zone in it on on load using current logged in user’s information, and used the same field in plugin.

Hope it helps..

Plugin on Retrieve Multiple in CRM 2015.


Recently we had a requirement to filter sub grid on one of the forms. We thought of using Plugin on Retrieve Multiple for this.

Here we were showing Opportunity Sub Grid on Account form.

So we created a view for Opportunity that will be used as Sub Grid. Used it as Related Record Sub Grid so that we can have the GUID of the Account record being passed to the plugin.

The problem we faced à Sorting and Paging stopped working for the Sub Grid.

http://crmtipoftheday.com/2015/10/05/limitations-of-retrieve-plugins/v

</p>
<p>void IPlugin.Execute(IServiceProvider serviceProvider)<br />
{<br />
// Obtain the execution context from the service provider.<br />
IPluginExecutionContext context = (IPluginExecutionContext)<br />
serviceProvider.GetService(typeof(IPluginExecutionContext));</p>
<p>// Obtain the organization service reference.<br />
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));<br />
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);</p>
<p>// The InputParameters collection contains all the data passed in the message request.<br />
if (context.InputParameters.Contains("Query") &amp;&amp; context.InputParameters["Query"] is QueryExpression &amp;&amp; context.MessageName == "RetrieveMultiple")<br />
{<br />
QueryExpression qe = (QueryExpression)context.InputParameters["Query"];<br />
if (qe.EntityName == "opportunity")<br />
{<br />
string currentCustomerId = string.Empty;<br />
ConditionExpression[] filters = qe.Criteria.Conditions.ToArray();<br />
foreach (var filter in filters)<br />
{<br />
currentCustomerId = filter.Values[0].ToString();<br />
}</p>
<p>FetchXmlToQueryExpressionRequest req = new FetchXmlToQueryExpressionRequest();<br />
req.FetchXml = "&lt;fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'&gt;" +<br />
"&lt;entity name='opportunity'&gt;" +<br />
" &lt;attribute name='name' /&gt;" +<br />
"&lt;attribute name='customerid' /&gt;" +<br />
"&lt;attribute name='estimatedvalue' /&gt;" +<br />
"&lt;attribute name='statuscode' /&gt;" +<br />
"&lt;attribute name='opportunityid' /&gt;" +<br />
"&lt;order attribute='name' descending='false' /&gt;" +<br />
"&lt;link-entity name='account' from='accountid' to='parentaccountid' alias='ad'&gt;" +<br />
" &lt;filter type='and'&gt;" +<br />
" &lt;filter type='or'&gt;" +<br />
" &lt;condition attribute='accountid' operator='eq' uiname='aaass' uitype='account' value=' " + currentCustomerId + "' /&gt;" +<br />
" &lt;condition attribute='accountid' operator='under' uiname='aaass' uitype='account' value='" + currentCustomerId + "' /&gt;" +<br />
"&lt;/filter&gt;" +<br />
"&lt;/filter&gt;" +<br />
"&lt;/link-entity&gt;" +<br />
"&lt;/entity&gt;" +<br />
"&lt;/fetch&gt;";<br />
FetchXmlToQueryExpressionResponse resp = (FetchXmlToQueryExpressionResponse)service.Execute(req);<br />
context.InputParameters["Query"] = resp.Query;</p>
<p>}<br />
}</p>
<p>

Hope it helps..

Advertisements

The records were not updated because the following Microsoft Dynamics CRM fields were not found during Import in CRM 2015.


Hi,
Was getting the below error while trying to import few records

The reason being there were two field in the entity having same Display Name. Renaming one of the fields fixed the issue and import ran successfully.

Hope it helps ..

Add Find Columns to Lookup View in CRM.


Hi,

Recently we had a requirement to search based on a particular attribute within the lookup view. The initial thought was to add a Find Columns to the lookup view. But then realized we do not have option of adding Find Columns to the lookup view.

The next thought was if I add that particular field to the list of Find Columns in Quick Find view will it work in Lookup View also? And it worked, basically adding any fields in the Find Column will make it Searchable.

The search works properly in the Lookup View as well as Lookup Inline View.

Hope it helps..

Sample Fetch XML Report using Multivalued Parameter (in Operator) in CRM


Hi,

Sharing a sample report which shows the usage of Multi Value parameter in filter.

Replace the Condition generated in the Fetch xml query using Advanced Find

As following

Create another DataSet to provide value for @gendercodevalue parameter.

Set @gendercodevalue parameter as following ( internal – if we do not want user to select or specify value for it in report)

Preview:

Hope it helps..

Advertisements

Missing New button in Quote Line entity for creating new views in CRM 2015.


Hi,

We found the New button was missing in Quote Line when we tried to creating the new views.

The work around is to use “Save As” and crate new view.

Hope it helps..