Category Archives: MS Dynamic CRM 2011

UTC time and Local time in CRM 2011

How to convert UTC time into local time in CRM 2011

Sometimes, we need to Convert UTC time into local time for various reasons. If you are in that condition, here is the some lines of code for you to do it.

private static string RetrieveLocalTimeFromUTCTime(DateTime utcTime, string crmUri)
{
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
Uri organizationUri = new Uri(crmUri);

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
{
IOrganizationService _serviceProxy = (IOrganizationService)serviceProxy;

var _timeZoneCode = _serviceProxy.RetrieveMultiple(
new QueryExpression(“usersettings”)
{
ColumnSet = new ColumnSet(“timezonecode”),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression(“systemuserid”, ConditionOperator.EqualUserId)
}
}
}).Entities[0].Attributes[“timezonecode”];

var request = new LocalTimeFromUtcTimeRequest();
request.TimeZoneCode = (int)_timeZoneCode;
request.UtcTime = utcTime.ToUniversalTime();

var response = (LocalTimeFromUtcTimeResponse)_serviceProxy.Execute(request);

return response.LocalTime.ToString();
}
}

Advertisement

Leave a comment

Filed under Convert UTC time into Local time, MS Dynamic CRM 2011

CRM 2011 SOP Integration Mode

How to turn on SOP Integration Mode in CRM 2011

If you want to integrate your CRM 2011 Organization with a separate ERP or Finance system using a product like Scribe or SmartConnect, Dynamics CRM 2011 SOP Integration Mode will make it much easier for you to do. It is not known much and hardly documented setting.

The “IsSOPIntegrationEnabled” setting makes the following changes:

  • Replaces the ‘Create Invoice’ button on the Sales Order ribbon with a ‘Submit Order’ button
  • Enables a series of ‘Submitted Status’ fields on the Sales Order entity and Sales Order properties window
  • Enables a ‘Submitted’ statecode value for the Sales Order entity
  • Allows you to specify an ‘Integration User’ that can then make changes to Sales Order and Invoice records through the SDK that would normally be read-only to all other users.

With integration mode enabled, this process flow is possible:

  1. CRM User submits a Sales Order (making the record read-only to normal users)
  2. Integration software picks up the CRM sales order and creates a record in your ERP system
  3. The CRM ‘Integration User’ account can write back to the CRM Sales Order to indicate that it has been successfully created in your ERP system.  This would need to happen through the SDK running in the context of the user account that has been marked as the integration user.
  4. The Finance Department can review the sales order, apply taxes and currency changes etc. to the record, then post it in the ERP system.
  5. The Integration picks up posted Invoices from your ERP system and creates a copy in CRM for reference by CRM users.
  6. As payments are applied to the invoice in your ERP system, another integration updates the payment status of the copy Invoice in CRM.

Turning this mode on takes a few steps, the “IsSOPIntegrationEnabled” value is held in the OrganizationBase table of your CRM Organization database.  Updates direct to SQL are unsupported, but Sonoma Partners have recently released this tool  that allows you to make changes to the OrganizationBase table in a supported way. But if you want to do it by yourself with C#, the following lines of codes will help you to do so.

public static void ActivateIntegrationMode(string CRM_USERNAME, string CRM_PASSWORD, string CRM_DOMAIN, string CRM_ORG_URL, bool turnOn)
{
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential(CRM_USERNAME, CRM_PASSWORD, CRM_DOMAIN);
Uri organizationUri = new Uri(CRM_ORG_URL);

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
{
IOrganizationService _serviceProxy = (IOrganizationService)serviceProxy;

Guid orgId = ((WhoAmIResponse)_serviceProxy.Execute(new WhoAmIRequest())).OrganizationId;
Guid userId = ((WhoAmIResponse)_serviceProxy.Execute(new WhoAmIRequest())).UserId;

//– Update Org to SOP Integration Mode
if (turnOn)
{
Entity org = new Entity(“organization”);
org[“issopintegrationenabled”] = true;
org[“organizationid”] = orgId;
_serviceProxy.Update(org);

//– Update User to Integration Mode
Entity user = new Entity(“systemuser”);
user[“systemuserid”] = userId;
user[“isintegrationuser”] = true;
_serviceProxy.Update(user);
}
else
{
Entity org = new Entity(“organization”);
org[“issopintegrationenabled”] = false;
org[“organizationid”] = orgId;
_serviceProxy.Update(org);

//– Update User to Integration Mode
Entity user = new Entity(“systemuser”);
user[“systemuserid”] = userId;
user[“isintegrationuser”] = false;
_serviceProxy.Update(user);
}
}
}

[Reference: http://crmuk.wordpress.com/2012/11/21/crm-2011-sop-integration-mode/]

Leave a comment

Filed under MS Dynamic CRM 2011, SOP Integration Mode

Passing Calling User to an Aspx Page from Sitemap in CRM 2011

How to Pass the Calling User to an Aspx Page from Sitemap in CRM 2011

First, you need to create a simple HTML file and put the following codes in that page. Add the HTML file into the web resource. Call that file from your Sitemap. By the way, don’t forget to redirect to your aspx page in the HTML file. 🙂

<HTML><HEAD><TITLE></TITLE></HEAD>
<BODY onload=redirectAspxPage(); contentEditable=true>
<SCRIPT type=text/javascript src=”../ClientGlobalContext.js.aspx”></SCRIPT>

<SCRIPT type=text/javascript>
function redirectAspxPage() {

var userid = window.parent.Xrm.Page.context.getUserId();

window.location.href = “http://YOUR_URL/YOUR_PAGE.aspx?userid= ” + userid;
}
</SCRIPT>
</BODY></HTML>

2 Comments

Filed under Passing Calling User to an Aspx Page from Sitemap

Disable Form Fields in CRM 2011

How to Disable Form Fields in CRM 2011

This article is different from the previous one. This time, we are going to disable all the fields on a form in CRM 2011. The sample Java script is shown below.

function disableFormFields(onOff) {
Xrm.Page.ui.controls.forEach(function (control, index) {
if (doesControlHaveAttribute(control)) {
control.setDisabled(onOff);
}
});
}

function doesControlHaveAttribute(control) {
var controlType = control.getControlType();
return controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”;
}

Leave a comment

Filed under Disable Form Fields, MS Dynamic CRM 2011

Readonly Entity Form in CRM 2011

How to Redirect to a Readonly Entity Form in CRM 2011

Sometimes, if you want to have a readonly form in CRM 2011, this article is what you want. We can call the following URL for readonly form in CRM 2011.

http://SERVER Name/ORG NAME/_forms/print/custformprint.aspx?

Query String Parameters

Parameter Value Comment
allsubgridspages Optional
true or false.
Default is false.
If CRM form has a Sub-Grid in it, this parameter decides whether to show Paging for the SubGrids. If set to true, it will show all the records of Sub-Grid, without any Pagination.
id Mandatory GUID. Guid of CRM entity record
formid GUID.
Optional
Form Id, if not given it and if there are multiple forms available for given entity it will follow CRM’s way of showing appropriate form.
objectType Mandatory Number. Object Type Code for Entity

Here is the sample Java script for that.

changeToReadOnlyPage = function()Here is the sample JavaScript function.

{
var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_READONLY = 3;

if( Xrm.Page.ui.getFormType()== CRM_FORM_TYPE_CREATE)
window.location =Xrm.Page.context.getServerUrl() + “/” + Xrm.Page.context.getOrgUniqueName() +
“/_forms/print/custformprint.aspx?objectType=” + Xrm.Page.context.getQueryStringParameters().etc;
else if( Xrm.Page.ui.getFormType() != CRM_FORM_TYPE_READONLY)
window.location = Xrm.Page.context.getServerUrl() + “/” + Xrm.Page.context.getOrgUniqueName() +
“/_forms/print/custformprint.aspx?id=” + Xrm.Page.data.entity.getId()+ “&objectType=” + Xrm.Page.context.getQueryStringParameters
().etc;
}

Leave a comment

Filed under MS Dynamic CRM 2011, Readonly Entity Form

How to create a custom Ribbon button in MS Dynamic CRM 2011

  • Go to Settings -> Customization -> Solutions.
  • Click ‘New’ button on Solutions page.
  • Fill up Display Name, Name, Publisher and Version as shown in the below figure and click ‘Save’.
  • Select ‘Entities’ and click ‘Add Existing’. A popup window will come out and choose any one of the entities to which you want to add the ribbon button. I will choose ‘Case’ entity here.

When you see the following dialog, choose ‘No, do not include required components’ as we are just going to add a custom ribbon button.

  • We will add the icons (16×16 and 32×32) to be used for the ribbon icon. Choose ‘Web Resources’ and click ‘New’ button as shown in the figure.
  • Fill up Name, Display Name, Type and upload the icon file as shown in the figure and click ‘Save and Close’.
  • Repeat the step no.6, and upload 32×32 icon file with the file name of ‘btn_dialog32’.
  • Add another web resource and fill up Name, Display Name, Type and click ‘Text Editor’ as shown in the figure.
  • Write java script as shown in the figure.

(You can write java script in TextEditor or you can upload java script file.)

After adding the javascript, you will see the URL as shown in the below figure. Then click ‘Save and Close’.

  • Now you will see there are two icons and one java script in your web resources. Click ‘Save and Close’.
  • Select the solution you have created just now and click ‘Export’. When the system prompts the dialog, click ‘Publish All Customizations’ button and after that, click ‘Next’ button.

Ignore all the warnings and click ‘Next’.

Export as ‘Unmanaged’.

(You need to export the solution you created so that you can add your customized ribbon button.)

  • The exported file is saved as in the form of zip file. Find the zip file and extract it. There is a file called ‘customizations.xml’. Open the file and look for <RibbonDiffXml> tag in order to edit it.
  • Replace existing <RibbonDiffXml> section with the following:

<RibbonDiffXml>

<CustomActions>

<CustomAction Id=”CI_formlevelHelloRibbonButton” Location=”Mscrm.Form.incident.MainTab.Actions.Controls._children” Sequence=”99″>

<CommandUIDefinition>

<Button Id=”B_formbuttonHelloRibbonButton” Command=”Cmd_DialogHelloRibbonButton”

LabelText=”Hello Ribbon” ToolTipTitle=”Hello Ribbon Button” ToolTipDescription=”This is my first ribbon button.” TemplateAlias=”o1″

Image16by16=”$webresource:new_btn_dialog16″ Image32by32=”$webresource:new_btn_dialog32″/>

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplates Id=”Mscrm.Templates”></RibbonTemplates>

</Templates>

<CommandDefinitions >

<CommandDefinition Id=”Cmd_DialogHelloRibbonButton”>

<EnableRules>

<EnableRule Id=”Mscrm.Enabled” />

</EnableRules>

<DisplayRules />

<Actions>

<JavaScriptFunction FunctionName=”HelloCustomRibbon” Library=”$webresource:new_showWelcomeMessge” >

</JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules />

<DisplayRules />

<EnableRules />

</RuleDefinitions>

<LocLabels />

</RibbonDiffXml>

  • Unzip the files and import into the system as shown in the figure.

Ignore the warning and click ‘Next’.

After importing, publish all the customizations again.

  • After that, Go to Service -> Cases and open one of the cases. You will see a new ribbon button on the case form. When you click that ribbon button, you will see the message as shown in the figure.

Leave a comment

Filed under Custom Ribbon, MS Dynamic CRM 2011