Enabling plug-in for Change Business Unit and Change Manager for systemuser entity.


Hi,

Normally we can’t attach plugin when we change business unit or the manager for a system user.

However we can do this in an unsupported manner,

The message for Change Business Unit is ‘setbusiness’.

Open your OrgName_MSCRM database and run the following query.

update sdkmessagefilterbase
set isCustomProcessingStepAllowed=1
where 
sdkmessageid=(select sdkmessageid from sdkmessagebase where name=’setbusiness’)
and
primaryObjectTypecode=’8′

And for Change Manager

update sdkmessagefilterbase
set isCustomProcessingStepAllowed=1
where 
sdkmessageid=(select sdkmessageid from sdkmessagebase where name=’setparent’)
and
primaryObjectTypecode=’8′

Bye..

 

CRM 3 to CRM 4 upgrade : two things to keep in mind.


Hi,

We had recently upgraded from CRM 3 to CRM 4. There were two issues we got stuck with.

One was following,

whenever we were saving our sales order form, we were receiving the following error

“One or more of the option values for this picklist are not in the range of allowed values”

However the same thing was working absolutely fine in CRM 3.

Finally we realized that this was because of one of the dummy picklist attribute. Dummy in a sense that for that attribute, values were being displayed using AddOption method of picklist and it had no corresponding (Data) Value defined.

So if a picklist field doesn’t have a corresponding data value defined for it , and if we try to save that form, it would throw this error “One or more of the option values for this picklist are not in the range of allowed values”. But only in case of CRM 4. In CRM 3, it would allow us to save the form.

And the second thing we realized was this,

Suppose we have a custom entity with the following attributes

Name (nvarchar) and Type (picklist) and we have defined a default value for the Type picklist attribute.

Now using CrmService.asmx Web Service if we are creating record of that particular entity and only specifying value for Name attribute,

a new record would get created with name specified by us and for the other picklist field, for which we didn’t specify anything while creating the record, it would have the default value for that picklist attribute set to it . However this would happen only in case of CRM 4.0

For CRM 3, a new record would get created but it would only contain the value for the Name field. The Type field would remain blank as we hadn’t defined any value for creating while creating the record using CrmService.

So in CRM 4, platform layer do take into considerationg the default value set for fields while the record is getting created using CrmService.

Bye.

Customizing Convert Lead dialog box in CRM 4


This is an unsupported customization, where we would be hiding the account option from the convert lead dialog box.

For doing so,

Find and open the conv_lead.aspx page on your crm server.

Inside the function window.onload add the following code

 function window.onload( )
{

// add the following line of code to hide the checkbox
document.getElementById('cbAddAccount').style.display ='none';

and to hide the label by commenting out the following tag

<label for="cbAddAccount">
<% =Microsoft.Crm.CrmEncodeDecode.CrmHtmlEncode(Util.GetFmtObjName
(Util.Account, Util.NameFormatStyle.Singular)) %></label>


Just remember this is unsupported.

Or use the following JavaScript

document.getElementById(‘cbAddAccount’).style.display = “none”;
document.getElementById(‘cbAddAccount’).parentNode.parentNode.childNodes[1].childNodes[0].style.display = “none”;

Bye.

Understanding Security Context in CRM 4 Workflow.


A “on demand” workflow runs under the security context of the user who ran that workflow using the “Run workflow” option.

In all other cases workflow would always run under the context of the user who owns that workflow.

Let’s take a simple example to understand this

Suppose this is our workflow, which is registered against lead entity and which runs while a lead record is created and can be run “on demand” as well. It updates one of the fields in the lead record.

wf1

The owner of the record is “Nishant Rana” i.e. me.
Now if i log into the CRM and create a new lead record. The workflow would get triggered and update the record.

Now if we check the properties we would find this

wf1 

Now suppose another user logs into CRM and creates a new lead record. The workflow would get triggered and it will update the lead record.

Here it would show the workflow owner’s name for the modified by field.

wf3

And if the same user is running the workflow manually using “Run Workflow” option, the modified by would get updated with the uuser’s name and not the owner of the workflow.

wf4

Bye..

Sample code for TargetCompoundSalesOrder and CompoundCreate Message


Just a sample code on how we can use the above classes

// retrieve the sales order class
TargetRetrieveSalesOrder targetSalesOrder =
 new TargetRetrieveSalesOrder();
targetSalesOrder.EntityId =
new Guid("guid");
RetrieveRequest myRReq = new RetrieveRequest();
myRReq.ColumnSet = new AllColumns();
myRReq.Target = targetSalesOrder;
RetrieveResponse myRRes = (RetrieveResponse)service.Execute(myRReq);
salesorder mySalesOrder =(salesorder)myRRes.BusinessEntity;
// setting guid to null else duplicate key error
mySalesOrder.salesorderid = null;
// retrieve all the sales order detail for the sales order
ConditionExpression expression = new ConditionExpression();
expression.AttributeName = "salesorderid";
expression.Operator = ConditionOperator.Equal;
expression.Values =
 new string[] { "guid" };
FilterExpression expression2 = new FilterExpression();
expression2.FilterOperator = LogicalOperator.And;
expression2.Conditions = new ConditionExpression[] { expression };
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.salesorderdetail.ToString();
query.ColumnSet = new AllColumns();
query.Criteria = expression2;
BusinessEntityCollection entitys = service.RetrieveMultiple(query);
salesorderdetail[] salesDetail=
new salesorderdetail[entitys.BusinessEntities.Length];
int i = 0;
foreach(BusinessEntity be in entitys.BusinessEntities)
{
salesDetail[i] =(salesorderdetail) be;
salesDetail[i].salesorderdetailid = null;
i++;
}
// initialize and set properties for TargetCompoundSalesOrder class
TargetCompoundSalesOrder tcSalesOrder =
new TargetCompoundSalesOrder();
tcSalesOrder.SalesOrder = mySalesOrder;
tcSalesOrder.SalesOrderDetails = salesDetail;
// use CompoundCreateRequest class
CompoundCreateRequest ccReq = new CompoundCreateRequest();
ccReq.Target = tcSalesOrder;
CompoundCreateResponse ccRes =
(CompoundCreateResponse)service.Execute(ccReq);

Bye..

Advertisements

Clone Records in CRM


was just looking for different ways we can clone a record in CRM.

These are the different articles that i found :-

Cloning records through an ASP.NET page

http://blogs.inetium.com/blogs/microsoftcrm/archive/2009/04/27/cloning-records-in-microsoft-crm-4-0-using-ajax-controls.aspx

Cloning records without any code by making use of self-referential relationship and mapping

http://rc.crm.dynamics.com/rc/regcont/en_us/op/articles/cloneRecords.aspx

Cloning records through workflow

http://www.dynamicscrmtrickbag.com/2009/08/29/clone-workflow/

Cloning records through JavaScript

http://ronaldlemmen.blogspot.com/2007/05/clone-record.html

And below is the code which i have used to clone Sales Order with all related sales order details

public void CloneSalesOrder(string salesOrderId, CrmService crmService)
{
Guid id = new Guid(salesOrderId);
// get all the attributes values using AllColumns
salesorder originalSalesOrder = (salesorder)crmService.
Retrieve(EntityName.salesorder.ToString(), id, new AllColumns());
salesorder cloneSalesOrder = new salesorder();
// assign the original sales order to the cloned one
cloneSalesOrder = originalSalesOrder;
cloneSalesOrder.name = "Cloned SalesOrder";
// set sales order id and order number as null
cloneSalesOrder.salesorderid = null;
cloneSalesOrder.ordernumber = null;
TargetCreateSalesOrder order = new TargetCreateSalesOrder();
order.SalesOrder = cloneSalesOrder;
CreateRequest request = new CreateRequest();
request.Target = order;
CreateResponse response = (CreateResponse)crmService.Execute(request);
// clone all the line items as well
CloneSalesOrderLineItems(salesOrderId, response.id.ToString(),
crmService);
}
private void CloneSalesOrderLineItems(string objPoId, string
objClonedPoId, CrmService service)
{
CrmService crmService = service;
//Retrieve all the sales order details from the original sales
//order record
ConditionExpression expression = new ConditionExpression();
expression.AttributeName = "salesorderid";
expression.Operator = ConditionOperator.Equal;
expression.Values = new string[] { objPoId.Trim() };
FilterExpression expression2 = new FilterExpression();
expression2.FilterOperator = LogicalOperator.And;
expression2.Conditions = new ConditionExpression[] { expression };
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.salesorderdetail.ToString();
query.ColumnSet = new AllColumns();
query.Criteria = expression2;
BusinessEntityCollection entitys = crmService.RetrieveMultiple(query);
if (entitys != null)
{
// one by one create sales order detail record and set its sales
//order id as the new cloned record id
foreach (salesorderdetail salesorderdetail in entitys.BusinessEntities)
{
salesorderdetail salesorderdetail2 = new salesorderdetail();
salesorderdetail2 = salesorderdetail;
Guid guid = new Guid(objClonedPoId);
salesorderdetail2.salesorderid = null;
salesorderdetail2.salesorderdetailid = null;
Lookup lookup = new Lookup();
lookup.Value = guid;
salesorderdetail2.salesorderid = lookup;
salesorderdetail2.salesorderid.Value = lookup.Value;
TargetCreateSalesOrderDetail detail = new
TargetCreateSalesOrderDetail();
detail.SalesOrderDetail = salesorderdetail2;
CreateRequest request = new CreateRequest();
request.Target = detail;
CreateResponse response = (CreateResponse)crmService.Execute(request);
}
}
}

 

Bye..