Archive

Archive for September, 2011

Unexpected error while bulk edit

September 22, 2011 6 comments

Hi,

You may come across below error screen when you try to bulk edit records.

Bulk Edit Error

Bulk Edit Error

When you verify the event viewer for issue log, you may observe “Message: INVALID_WRPC_TOKEN: Validate WRPC Token: WRPCTokenState=Invalid” .

Reason:-

  • The fundamental problem is that CRM 2011 now expects additional parameters on the query string that contain a Token

Fix :-

  • We can disable the CRM token checks via Registry change.
  • Create a DWORD registry key named IgnoreTokenCheck under “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM” and set the value to 1,
  • Recycle the CrmAppPool application pool for the change to take effect (or) restart machine

Steps to change the registry:-

  • Open Registry Editor (Run -> regedit)
  • Navigate to “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM” node
  • Add a new Key “IgnoreTokenCheck” and set value to 1
  • Refer below screen
IgnoreTokenCheck

IgnoreTokenCheck

Hope it helps 🙂

 

Advertisement

Missing prvReadAsyncOperation privilege exception

September 21, 2011 3 comments

Hi,

Today my plug-in has thrown “Missing prvReadAsyncOperation privilege ” exception for user with one of the security role.

Fix:-

  • We need to grant Read Priveliege of System Job for the security role
  • Open the Security Role and go to Customization tab
  • Refer below screen
prvreadasync-privilage

prvreadasync-privilage

 

Hope it helps 🙂

Check user security role in Plug-ins CRM 2011

September 20, 2011 Leave a comment

Hi,

Below is the code snippet to check current user security role in Plug-in.

private void CheckUserRole(IOrganizationService service, Guid userID)

{

QueryExpression query = new QueryExpression();

query.EntityName = “role”; //role entity name

ColumnSet cols = new ColumnSet();

cols.AddColumn(“name”); //We only need role name

query.ColumnSet = cols;

ConditionExpression ce = new ConditionExpression();

ce.AttributeName = “systemuserid”;

ce.Operator = ConditionOperator.Equal;

ce.Values.Add(userID);

//system roles

LinkEntity linkRole = new LinkEntity();

linkRole.LinkFromAttributeName = “roleid”;

linkRole.LinkFromEntityName = “role”; //FROM

linkRole.LinkToEntityName = “systemuserroles”;

linkRole.LinkToAttributeName = “roleid”;

//system users

LinkEntity linkSystemusers = new LinkEntity();

linkSystemusers.LinkFromEntityName = “systemuserroles”;

linkSystemusers.LinkFromAttributeName = “systemuserid”;

linkSystemusers.LinkToEntityName = “systemuser”;

linkSystemusers.LinkToAttributeName = “systemuserid”;

linkSystemusers.LinkCriteria =new FilterExpression();

linkSystemusers.LinkCriteria.Conditions.Add(ce);

linkRole.LinkEntities.Add(linkSystemusers);

query.LinkEntities.Add(linkRole);

EntityCollection collRoles = service.RetrieveMultiple(query);

if (collRoles != null && collRoles.Entities.Count > 0)            {

foreach (Entity _entity in collRoles.Entities)                {

if (_entity.Attributes[“name”].ToString().ToLower() == “{Your rolename}”                    {

}

}

}

}

 

How do I call this method :-

public void Execute(IServiceProvider serviceProvider)

{

IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

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

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

          CheckUserRoles(service, context.UserId);

}

Hope it helps 🙂

How to change CRM form field’s label text and color using Jscript

September 15, 2011 1 comment

Hi,

Below is the sample JScript to change the color and text of  CRM form field’s  label; Place the code in JScript “onload” event

// To change color

if(crmForm.all.new_fieldname != null) {

var field = crmForm.all.new_fieldname_c; //”_c” is the caption (i.e.,Label)

if (field != null)

field.style.color = ‘gray’; //Specify your desired color

}

Same script work for both CRM 4.0 & CRM 2011

// To set the label

Xrm.Page.ui.controls.get(fieldname).setLabel(‘New label’);

🙂

Read Optionset value in Plugin CRM 2011

September 14, 2011 7 comments

Hi,

  Below is the sample code to read Picklist value (i.e., OptionSet Value) in CRM 2011

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] isEntity)

{

currEntity = (Entity)context.InputParameters[“Target”];

}

int statusValue = -1;

string statusText=string.empty;

if (currEntity .Attributes.Contains(“statecode”))

{

OptionSetValue optionState = currEntity .Attributes[“statecode”] as OptionSetValue;

statusValue = optionTimesheetState.Value;

statusText = optionTimesheetState.Text;

}

Hope it helps 🙂

Case statement in Select clause

September 13, 2011 Leave a comment

Hi,

Below is a sample query that has “CASE statement”  in SELECT clause

SELECT EmpID,

CASE
WHEN Salary>=2000 THEN ‘High Salaried’
WHEN Salary<=1000 THEN ‘Medium’
ELSE ‘Below Bar’
END

‘New Column’, *

FROM

Employee

Below is the screenshot for reference

CASE in SELECT Clause

CASE in SELECT Clause

Hope it helps 🙂

Workflows/Dialogs ownership in CRM 2011

September 10, 2011 Leave a comment

Hi,

Today i have come across useful article on “Ownership of  Workflows ” below are few excerpts

Q> Under what user’s context does the workflow execute? (If the workflow creates a record, who will be the owner of that new record?)

  • Automatically triggered workflows (such as a workflow that triggers on account create) will execute in the context of the owner of the workflow.
  • If the workflow is executed on-demand, the workflow will then execute in the context of the user who requests the workflow execution.
  • Dialogs are always on-demand then they always execute in the context of the user who started the dialog.

Refer below Q/A article by Gonzalo Ruiz

http://gonzaloruizcrm.blogspot.com/2011/05/processesworkflow-ownership-faqs.html#comment-form

Hope it helps 🙂

User does not have “prvSendEmail” privilage CRM 2011

September 9, 2011 4 comments

Hi,

In CRM 2011, while sending an email programatically you may come across “User doe not have SendAsUser Privilage” exception.

(Refer useful article on How to send an email https://rajeevpentyala.wordpress.com/2011/08/03/sending-an-email-using-crm-2011-plug-in/)

It would happen even all the security roles having this privilege (Refer below)

SendEmail Privilage

SendEmail Privilage

To fix the issue, solution is very simple

  • Open the SQL management Studio and connect to “orgname_mscrm” DB
  • Run below query
  • UPDATE UserSettings
    SET IsSendAsAllowed  = 1
    WHERE IsSendAsAllowed = 0

 

Refer below helpful article on the same

http://www.digital-transition.com/archives/2011/crm-2011-user-does-not-have-send-as-privilege/

Hope it helps 🙂

How to get Object Type Codes of Entities in CRM 2011

September 8, 2011 3 comments

Hi,

In this article i have explained different ways to fetch entities “Object Type Code”

  •  Using SQL Query :-

Get Object Type codes by Sql Query

Query>

SELECT ObjectTypeCode,*

FROM

ENTITYVIEW

Using JScript  :-

  • The “ObjectTypeCode” can be extracted from Query String using JScript
  • “ObjectTypeCode” resides in “etc” query string  parameter
  • Below is the JScript statement to get “ObjectTypeCode”

var currEntityObjTypeCode= Xrm.Page.context.getQueryStringParameters().etc

Key Points

  • Type codes below 10,000 are reserved for OOB entities.
  • Custom entities have a value greater than or equal to 10,000.

Note:- Custom entity object type codes may change during import and are not guaranteed to be the same between systems.

Getting Object Type Code by ‘Entity Name’ using Jscript

Below script uses CRM inbuilt logic and return the entity type code (or) object type code for the given entity name.

function getObjectTypeCodeByName(entityName) {

try {

var lookupService = new RemoteCommand(“LookupService”, “RetrieveTypeCode”);

lookupService.SetParameter(“entityName”, entityName);

var result = lookupService.Execute();

if (result.Success && typeof result.ReturnValue == “number”) {

return result.ReturnValue;

} else {

return null;

}

} catch (e) {

alert(“Error while getting ETC by Name – ” + e.description);

}

}

Hope it helps 🙂

Updating selected records in the contact Grid – CRM 2011

September 1, 2011 8 comments

Hi,

In CRM 2011, we can update selected records in the Grid using Ribbon customizations (i.e., by using a Custom Ribbon Button).

Ribbon button on Grid

Ribbon button on Grid

Steps:-

  • Create a new Solution called “Ribboncustomer” and add ‘contact’ entity and a newly created web resource called ”ribbon.js” with below function

function processrecords(selectedIds) {

if (selectedIds != null && selectedIds != “”) {

var strIds = selectedIds.toString();

var arrIds = strIds.split(“,”);

for (var indxIds = 0; indxIds < arrIds.length; indxIds++) {

updateRecords(arrIds[indxIds]);

}

}

else {

alert(“No records selected!!!”);

}

}

function updateRecords(contactId) {

//Use OData or Soap call to update the record using passed GUID

}

  • Publish the customizations
  • Export the Solutions and Save
  • Unzip the Solution and Open the “customizations.xml” using VS 2010.
  • search for <RibbonDiffXML> node
  • Replace  with below node

      <RibbonDiffXml>

<CustomActions>

<CustomActionId=Sample.Grid.contact.CustomTab.CustomActionLocation=Mscrm.Tabs._childrenSequence=40>

<CommandUIDefinition>

<TabId=Sample.Grid.contact.CustomTabCommand=Sample.Grid.contact.CustomTab

Title=$LocLabels:Sample.contact.CustomTab.Title

Description=$LocLabels:Sample.contact.CustomTab.DescriptionSequence=500>

<ScalingId=Sample.Grid.contact.CustomTab.Scaling>

<MaxSizeId=Sample.Grid.contact.CustomTab.FirstGroup.MaxSize

GroupId=Sample.Grid.contact.CustomTab.FirstGroup

Sequence=10Size=LargeMedium />

</Scaling>

<GroupsId=Sample.Grid.contact.CustomTab.Groups>

<GroupId=Sample.Grid.contact.CustomTab.FirstGroupCommand=Sample.Grid.contact.FirstGroupSequence=10

Title=$LocLabels:Sample.contact.CustomTab.FirstGroup.TitleTemplate=Mscrm.Templates.3.3>

<ControlsId=Sample.Grid.contact.CustomTab.FirstGroup.Controls>

<ButtonId=Sample.Grid.contact.CustomTab.FirstGroup.FirstButton

ToolTipTitle=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText

ToolTipDescription=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription

Command=Sample.Grid.contact.FirstButtonSequence=10  LabelText=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText

Alt=$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText

Image16by16=/_imgs/ribbon/AddEmail_16.pngImage32by32=/_imgs/ribbon/Email_32.pngTemplateAlias=o1 />

</Controls>

</Group>

</Groups>

</Tab>

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplatesId=Mscrm.Templates></RibbonTemplates>

</Templates>

<CommandDefinitions>

<CommandDefinitionId=Sample.Grid.contact.CustomTab>

<EnableRules>

<EnableRuleId=Mscrm.Enabled />

</EnableRules>

<DisplayRules>

<DisplayRuleId=Mscrm.CanWriteContact />

</DisplayRules>

<Actions/>

</CommandDefinition>

<CommandDefinitionId=Sample.Grid.contact.FirstGroup>

<EnableRules>

<EnableRuleId=Mscrm.Enabled />

</EnableRules>

<DisplayRules>

<DisplayRuleId=Mscrm.CanWriteContact />

</DisplayRules>

<Actions />

</CommandDefinition>

<CommandDefinitionId=Sample.Grid.contact.FirstButton>

<EnableRules/>

<DisplayRules/>

<Actions>

<JavaScriptFunctionLibrary=$webresource:new_ShowMessageFunctionName=processrecords>

                <CrmParameterValue=SelectedControlSelectedItemIds />

              </JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules>

<TabDisplayRuleTabCommand=Sample.Grid.contact.CustomTab>

<EntityRuleEntityName=contactContext=HomePageGrid />

</TabDisplayRule>

</TabDisplayRules>

<DisplayRules />

<EnableRules />

</RuleDefinitions>

<LocLabels>

<LocLabelId=Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText>

<Titles>

<Titlelanguagecode=1033description=Update Records />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.Description>

<Titles>

<Titlelanguagecode=1033description=A custom tab for the Contact entity. />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.FirstGroup.Title>

<Titles>

<Titlelanguagecode=1033description=Get IDs Group />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription>

<Titles>

<Titlelanguagecode=1033description=Get the selected GUID’s of Grid items />

</Titles>

</LocLabel>

<LocLabelId=Sample.contact.CustomTab.Title>

<Titles>

<Titlelanguagecode=1033description=Custom Tab />

</Titles>

</LocLabel>

</LocLabels>

</RibbonDiffXml>

 

The key node in the above XML is  <CrmParameterValue=”SelectedControlSelectedItemIds” />

<CommandDefinitionId=Sample.Grid.contact.FirstButton>

<EnableRules/>

<DisplayRules/>

<Actions>

<JavaScriptFunctionLibrary=$webresource:new_ShowMessageFunctionName=processrecords>

<CrmParameterValue=SelectedControlSelectedItemIds />

</JavaScriptFunction>

</Actions>

</CommandDefinition>

We are passing “SelectedControlSelectedItemIds” (i.e.,Selected record Guid’s) to the JScript function. Multiple Id’s seperate by ‘,’.

 

  • We are done with customization part, zip the files and Import the solution & publish all customizations.
  • Clear the cache and refresh the browser and you will get the custom tab with “Update Records” button.

** Below are few more key <CrmParameterValue> that can be passed as parameter **

SelectedEntityTypeCode : A number representing the unique type of entity for a record selected in a grid. The Entity type code will vary
between deployments.
SelectedEntityTypeName : A string representing the unique name of the entity for a record selected in a grid.
FirstSelectedItemId : Provides one GUID identifier as a string for the first item selected in a grid.
SelectedControlSelectedItemCount : The number of selected items in a grid.

SelectedControlSelectedItemIds : A string array of GUID Id values for all selected items in a grid.

SelectedControlAllItemCount : A string array of GUID Id values for all selected items in a grid.
SelectedControlAllItemIds : A string array providing the GUID Id values for all items displayed in a grid.
SelectedControlUnselectedItemCount : The number of unselected items in a grid.
SelectedControlUnselectedItemIds : A string array of GUID Id values for all unselected items in a grid.

Hope it helps 🙂