Advertisements

Archive

Archive for August, 2012

Disabling Assign ribbon button based on custom logic using jscript CRM 2011

In one of my requirement, I have to enable/disable “Assign” button on “Account” form based on one of my option set value (i.e.,accountcategorycode)

Assign Button On Account Form

Assign Button On Account Form

I followed below steps to achieve the requirement

  • Get the Account “Assign” ribbon button details from “sdk\resources\exportedribbonxml\ accountribbon.xml” file from the SDK
    • Open a note pad and copy below two nodes for reference
    • Copy <Button Id=”Mscrm.Form.account.Assign”> tag
    • Copy <CommandDefinition Id=”Mscrm.AssignPrimaryRecord”> tag
  • Create a new jscript webresoure “new_Account_Ribbon” with function “enableAssignButton” and publish
    • If the function returns true the “Assign” button gets enabled else disabled
    • Define your own custom logic (Refer my custom logic below)

function enableAssignButton() {

try {

var fldCategory = Xrm.Page.data.entity.attributes.get(“accountcategorycode”);

if (fldCategory && fldCategory.getValue()) {

if (fldCategory.getValue() == 100000007) {

return true;

}

}

return false;

} catch (e) {

alert(“Error while enabling Assign button: ” + e.description);

}

}

  • Create a new solution and include “Account” entity and export as Unmanaged solution
  • Extract the zip folder and open “customizations.xml” using visual studio
  • Navigate to <RibbonDiffXml> node
  • Replace with below node (Refer comments to understand)

<RibbonDiffXml>

<CustomActions>

<!– Location will be ID of the Button–>

<CustomAction Location=”Mscrm.Form.account.Assign” Id=”Form.account.DisableAssign”>

<CommandUIDefinition>

<!– Paste the Assign button tag which you copied to notepad–>

<Button Id=”Mscrm.Form.account.Assign” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign”

ToolTipDescription=”$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Assign”

Command=”Mscrm.AssignPrimaryRecord” Sequence=”33″

LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign”

Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign” Image16by16=”/_imgs/ribbon/Assign_16.png” Image32by32=”/_imgs/ribbon/Assign_32.png” TemplateAlias=”o1″ />

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

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

</Templates>

<CommandDefinitions>

<!– Paste the Assign button Command Definition which you copied to notepad –>

<CommandDefinition Id=”Mscrm.AssignPrimaryRecord”>

<EnableRules>

<EnableRule Id=”Mscrm.FormStateNotNew” />

<EnableRule Id=”Mscrm.AssignPrimaryPermission” />

<EnableRule Id=”Mscrm.NotOffline” />

<!– Add new Enable Rule–>

<EnableRule Id=”Form.account.AssignButton.EnableRule”/>

</EnableRules>

<DisplayRules>

<DisplayRule Id=”Mscrm.AssignPrimaryPermission” />

<DisplayRule Id=”Mscrm.NotClosedActivity” />

</DisplayRules>

<Actions>

<JavaScriptFunction FunctionName=”assignObject” Library=”/_static/_forms/form.js”>

<CrmParameter Value=”PrimaryEntityTypeCode” />

</JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules />

<DisplayRules />

<EnableRules>

<!– Define Enable Rule–>

<EnableRule Id=”Form.account.AssignButton.EnableRule”>

<CustomRule Library=”$webresource:new_Account_Ribbon” FunctionName=”enableAssignButton“>

</CustomRule>

</EnableRule>

</EnableRules>

</RuleDefinitions>

<LocLabels />

</RibbonDiffXml>

🙂

Advertisements

RoleService:VerifyCallerPrivileges failed. PrivilegeName: prvAssignWorkflowSession error in CRM 2011

August 20, 2012 1 comment

I was getting the below error when I was trying to add a User to a Team

RoleService::VerifyCallerPrivileges failed. User:, PrivilegeName: prvCreateWorkflowSession, PrivilegeId:, Depth: Basic, BusinessUnitId:

Fix

  • Provide access to the “Dialog Session” entity to the security role whom the current user belongs to
"Dialog Session" entity privilages

“Dialog Session” entity privilages

🙂

UserId & InitiatingUserId properties in Plugin of CRM

August 19, 2012 3 comments

In CRM plugin, “IExecutionContext” contains 2 properties

  • UserId
    • Gets the GUID of the user for whom the plug-in invokes “on behalf of”.
  • InitiatingUserId
    • Gets the GUID of the user under which the current pipeline is executing.

Consider a scenario

  • You have a user “RAJ” with “Sales Person” role with only “User Level” “Read” privilege on ‘Contact’
  • You have a plugin on Post Deletion of ‘Contact’ with name “PostContactDelete”
  • Assume in one particular scenario user “RAJ” should be able to delete a ‘Contact’
  • So you can run the “PostContactDelete” plugin in the user with “SystemAdministrator” role
    • (i.e., Set “Run in User’s Context” to User with admin role; In sample screen shot below I chosen my admin user whose name is  ‘CRM WaSu1)
Run in User Context

Run in User Context

  • When User “RAJ” logs in and try to delete ‘Contact’ the plug-in “PostContactDelete” fires. When you debug
    • IExecutionContext.UserId = GUID of  SystemAdministrator (i.e., OnBehalfOf User ‘RAJ’)
    • IExecutionContext. InitiatingUserId =GUID of  RAJ   (i.e., Actual User)

🙂

Configure Tracing and view trace log files in CRM

August 16, 2012 2 comments

Tracing is important in CRM especially when your plugin throw exceptions in Test or Production environments

We can configure and view the trace log file easily using “Crm Trace Log Viewer” tool and it work for both CRM 4.0 and 2011

Download

Once you download the tool

Configure Tracing

  • Double click on the “Crm Trace Log Viewer” Application
Crm Trace Log Viewer Application

Crm Trace Log Viewer Application

  • Configure Tracing by go to Tools –> Configure Tracing
Configure Tracing

Configure Tracing

  • Provide your CRM server machine IP or Name and click “Ok”
CRM server IP or Machine Name

CRM server IP or Machine Name

  • Provide the details as given below
    • Directory – Path where you want your log files to generate
    • Level & Schedule
Configuring Trace

Configuring Trace

View Trace Log Files

  • Once you run the CRM application log files get generate in the path which we provided
Trace Log File

Trace Log File

  • To view the logs, Go to File –> Open Log
Open the trace log

Open the trace log

  • Once you open the file, you can view the details in “Details” pane
Exception Details

Exception Details

Note – Don’t forget to disable the tracing after you are done with debugging.

  • To disable tracing, open the tool and uncheck the option “Trace Enabled” (Refer image #4)

Outlook Client Tracing

  • Using CRM 2011 “Diagnostics Tool”, we can enable/disable tracing in outlook client
  • Here is the link

🙂

Creating a plug-in on SavedQuery entity using CRM developer toolkit

August 13, 2012 3 comments

In one of my requirement I have to create a plugin on “SavedQuery” entity to filter the views

I was using CRM developer toolkit and when I open the “CRM Explorer” I did not find “SavedQuery” entity

Later I came to know that “CRM Explorer” show entities by ‘Display Name’ and there was entity with name ‘View’ for ‘SavedQuery’

SavedQuery in Developer Toolkit

SavedQuery in Developer Toolkit

Thought of sharing this though its simple observation

🙂

Fixing time zone issues while reading datetime fields using jscript in CRM 2011

When you read datetime field values using OData or SOAP , you may not get exact datetime values if your CRM application is using by users from different time zones.

We can fix the problem by using the “timezonebias” field from current users “UserSettings“

timezonebias & timezonedaylightbias are system-calculated fields based on the time zone of current user

Follow below steps to fix the problem

  • Read the “timezonebias” &“timezonedaylightbias”  field by querying  “UserSettings“ by current user id
  • Get your datetime field and substract the “timezonebias & timezonedaylightbias” fields to get exact value

Below is the script for the above steps

  • Read Current UserSettings

function RetrieveUserSettings(callBackFunction) {

try {

var serverUrl = Xrm.Page.context.getServerUrl();

var oDataEndpointUrl = serverUrl + “/XRMServices/2011/OrganizationData.svc/”;

//get current user id from context

var UserID = Xrm.Page.context.getUserId();

var RetrieveUserSetting = new XMLHttpRequest();

RetrieveUserSetting.open(“GET”, oDataEndpointUrl + “/UserSettingsSet(guid'” + UserID + “‘)”, true);

RetrieveUserSetting.setRequestHeader(“Accept”, “application/json”);

RetrieveUserSetting.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

RetrieveUserSetting.onreadystatechange = function () {

callBackFunction(this);

};

RetrieveUserSetting.send();

} catch (e) {

alert(“Error on RetrieveUserSettings method”);

}

}

  • Call the above function to get “timezonebias & timezonedaylightbias” fields

RetrieveUserSettings(RetrieveUserSettingCallBack);

  • Read the “timezonebias” & “timezonedaylightbias” field from Call Back function and substract it from your datatime field value

   function RetrieveUserSettingCallBack(retrievedUserSetting) {

try {

if (retrievedUserSetting.readyState == 4) {

if (retrievedUserSetting.status == 200) {

var retrievedUser = this.parent.JSON.parse(retrievedUserSetting.responseText).d;

// Assume you got datetime field to below object

var dateValue;

var actMinutes = dateValue.getMinutes();

alert(“Skewed datetime – ” + dateValue); 

if (userSettings.TimeZoneBias != null) { 
            dateValue.setMinutes(userSettings.TimeZoneBias * -1); 
        } 

if (userSettings.TimeZoneDaylightBias != null) { 
            dateValue.setMinutes(userSettings.TimeZoneDaylightBias * -1); 
        }
// Add the actual minutes

dateValue.setMinutes(actMinutes);

alert(“Exact datetime – ” + dateValue);

}

}

} catch (e) {

alert(e.Description);

}

}

Here is the article on handling the time zone differences  in Plug-ins

🙂

Filtering partylist entities using jscript in CRM

August 2, 2012 5 comments

In CRM, partylist Party List is a data type, using which you can set more than one type of entity records for a single field

For example,

  • In the ‘Appointment’ entity, field “requiredattendees” is a ‘Party List’ type
  • We can select multiple records of different      type (i.e., Accounts, Users, Contacts…)

In one of my requirement, I have to restrict the party list field to show only ‘Contacts’. (i.e., I can only choose Contacts)

We can achieve by setting below properties to partylist field using jscript

crmForm.all.requiredattendees.setAttribute(“defaulttype”, “2”);

crmForm.all.requiredattendees.setAttribute(“lookuptypes”, “2”);

crmForm.all.requiredattendees.setAttribute(“lookuptypeIcons”, “/_imgs/ico_16_2.gif”);

Here ‘2’ is the Entity Type Code of ‘Contact’ entity

After setting the properties, the partylist look as below with ‘Contact’ chosen as default and in disabled state to restrict other entity selction

Filtered Party List

Filtered Party List

In case you have to filter 2 entities, let’s say Contact & User you have to set “lookuptypes & lookuptypenames & lookuptypeIcons” properties

            lookuptypeIcons = ‘/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif’;

lookuptypenames = ‘contact:2:Contact,systemuser:8:User’;

lookuptypes = ‘2,8’;

crmForm.all.requiredattendees.setAttribute(“lookuptypes”, lookuptypes);

crmForm.all.requiredattendees.setAttribute(“lookuptypenames”, lookuptypenames);

crmForm.all.requiredattendees.setAttribute(“lookuptypeIcons”, lookuptypeIcons);

🙂