Advertisements

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 🙂

 

Advertisements

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 🙂