Category Archives: MS CRM 4.0

Index was out of range. Must be non-negative and less than the size of the collection- MS CRM 4.0

Most of the time you will get this error when you will try to retrieve data from Grid View, and it has no rows. But if you have rows in Grid View, make sure you have enabled view state. If you have already enabled view state but you are still getting this error and you have deployed your webapplication under ISV folder in MS CRM 4.0, then here is the issue.

MS CRM web.config file overrides setting of your web application, so you need to specifically change web.config file of MS CRM. You need
to change lines in web.config file like below

<pages buffer=”true” enableSessionState=”true” enableViewState=”true” validateRequest=”false”/>

                                   <sessionState mode=”InProc”/>

 

Enjoy !!!

 

Leave a comment

Filed under MS CRM 4.0

Order is edited by multiple users Error

In my current project we have integrated order with our financial system and also we are using third party tool to generate order line items. After some time in production we started getting issue “Order is edited by multiple users” , and we were getting this issue only some times. After doing lot’s of testing what I found my order update plugin is called multiple times. After doing lot’s debugging what I found in my plugin context.depth is 1 but ever time correlationId was different. So I solved this issue by including below code in my plugin

if (_CorrelationID == Guid.Empty)
_CorrelationID = Context.CorrelationId;
else
{
if (_CorrelationID != Context.CorrelationId)
return;
}
try
{
// rest of the code
}
catch()
{//handle exception}
finally
{
_CorrelationID= Guid.Empty;}
This piece of code fixed my issue

4 Comments

Filed under MS CRM 4.0, Workflow & Plugin Development

An error occurred while parsing EntityName

While integrating CRM orders to our custom financial system webservice I got error “An error occurred while parsing EntityName” in my plugin. Our custom financial service accepts xml string as input, so while sending data in xml form, sometime account name contains special character like ‘&’ which is a illigal character in xml.so I wrote below function to replace illigal characters in xml request

private string FormatText(string XmlRequest)
{
string _ModifiedXML = XmlRequest.Replace(“&”, “&”);
_ModifiedXML = _ModifiedXML.Replace(“”, “>”);
_ModifiedXML = _ModifiedXML.Replace(“‘”, “'”);
_ModifiedXML = _ModifiedXML.Replace(“””, “"”);

return _XmlRequest;
}

Hope it will help somebody !!!

Leave a comment

Filed under MS CRM 4.0

Get Max value using Javascript

 If you want to fetch Max value from CRM entity record using Javascript, you can use below code, remember to change entity and field name accordingly

var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.

var xml = “<?xml version=’1.0′ encoding=’utf-8’?>”+

“<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/'”+

” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance'”+

” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>”+

authenticationHeader+

“<soap:Body>”+

“<RetrieveMultiple xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>”+

“<query xmlns:q1=’http://schemas.microsoft.com/crm/2006/Query'”+

” xsi:type=’q1:QueryExpression’>”+

“<q1:EntityName>EntityName</q1:EntityName>”+ //change entity name

“<q1:ColumnSet xsi:type=’q1:ColumnSet’>”+

“<q1:Attributes>”+

“<q1:Attribute>FieldName</q1:Attribute>”+ //change field name

“</q1:Attributes>”+

“</q1:ColumnSet>”+

“<q1:Orders>” +

“<q1:Order>” +

“<q1:AttributeName>FieldName</q1:AttributeName>” + //change field name

“<q1:OrderType>Descending</q1:OrderType>” +

“</q1:Order>” +

“</q1:Orders>” +

“</query>”+

“</RetrieveMultiple>”+

“</soap:Body>”+

“</soap:Envelope>”;

// Prepare the xmlHttpObject and send the request.

var xHReq = new ActiveXObject(“Msxml2.XMLHTTP”);

xHReq.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);

xHReq.setRequestHeader(“SOAPAction”,”http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple&#8221;);

xHReq.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8″);

xHReq.setRequestHeader(“Content-Length”, xml.length);

xHReq.send(xml);

// Capture the result.

var resultXml = xHReq.responseXML;

// Check for errors.

var errorCount = resultXml.selectNodes(‘//error’).length;

if (errorCount != 0)

{

var msg = resultXml.selectSingleNode(‘//description’).nodeTypedValue;

alert(msg);

}

else

{

var results = resultXml.getElementsByTagName(‘BusinessEntity’);

var msg = “”;

if (results.length == 0)

{

alert(msg);

return;

}

else

{

if(results[0].selectSingleNode(‘./q1:FieldName’)!=null)

{

var MaxValue = results[0].selectSingleNode(‘./q1:FieldName’).nodeTypedValue;   //change name of the field to get Max value

alert(MaxValue);

}

}}

Leave a comment

Filed under JS Script, MS CRM & Javascript

Using CompoundUpdateRequest in Dynamics CRM 4.0

Sometime when we are integrating ms crm with another application we need to send CRM data to another application and also need to keep track if data is already sent or not. For example if you are sending sales order and sales order line items and you need to update sales order and line item after sending, you can use  compoundupdaterequest message to update sales order and order line items in one go.

 

private BusinessEntityCollection ReadAllOrderLineItems(Guid _ID, ICrmService _iService)

        {

            RetrieveMultipleResponse retrieved = null;

            try

            {

                ConditionExpression _Condition = new ConditionExpression();

                _Condition.Operator = ConditionOperator.Equal;

                _Condition.AttributeName = “salesorderid”;

                _Condition.Values = new object[] { _ID };

                 FilterExpression _Filter = new FilterExpression();

                _Filter.FilterOperator = LogicalOperator.And;

                _Filter.Conditions.AddRange(new ConditionExpression[] { _Condition });

                 QueryExpression query = new QueryExpression();

                query.ColumnSet = new AllColumns();

                query.Criteria = _Filter;

                query.EntityName = “salesorderdetail”;

                RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();

                retrieve.Query = query;

                retrieve.ReturnDynamicEntities = true;

                retrieved = (RetrieveMultipleResponse)_iService.Execute(retrieve);

            }

            catch (SoapException Ex)

            {

                throw Ex;

            }

            catch (Exception Excep)

            {

                throw Excep;

            }

            return retrieved.BusinessEntityCollection;

         }

//Get all orderline items for particular salesorderid
BusinessEntityCollection _OrderLineItems = ReadAllOrderLineItems(_SalesorderID,_iCrmService); //I have written this function to fetch all order line items based on salesorder id.
 //Create Dynamic entity array to store salesorderdetails
 DynamicEntity[] _SalesorderDetailArr=new DynamicEntity[_OrderLineItems.BusinessEntities.Count];
 for(int i=0; i<_OrderLineItems.BusinessEntities.Count; i++)
            {
               //get salesorder key
                DynamicEntity _ExistingSalesorderItem = (DynamicEntity)_OrderLineItems.BusinessEntities[i];
 // create properties for sales order detail, in my example I have created a bit field in sales order and sales order detail

                DynamicEntity _Salesorderitem=new DynamicEntity();
                _Salesorderitem.Name = “salesorderdetail”;
                 //Add property to set created flag
                 CrmBooleanProperty _Created = new CrmBooleanProperty();
                _Created.Name = “new_created”;
                _Created.Value = new CrmBoolean();
                _Created.Value.Value = true;
                 _Salesorderitem.Properties.Add(_Created);
                 //set key property
                KeyProperty _SalesorderDetailKey = new KeyProperty();
                _SalesorderDetailKey.Name = “salesorderdetailid”;
                _SalesorderDetailKey.Value = new Key();
                _SalesorderDetailKey.Value.Value = ((Key)_ExistingSalesorderItem.Properties[“salesorderdetailid”]).Value;
                _Salesorderitem.Properties.Add(_SalesorderDetailKey);
                _SalesorderDetailArr[i] = _Salesorderitem;
            }

            DynamicEntity _Salesorder = new DynamicEntity();
            _Salesorder.Name = “salesorder”;
            _Salesorder.Properties.Add(new KeyProperty(“salesorderid”, new Key(_ID)));
            CrmBooleanProperty _Created = new CrmBooleanProperty();
            _Created.Name = “new_created”;
            _Created.Value = new CrmBoolean();
            _Created.Value.Value = true;
            _Salesorder.Properties.Add(_Created);
            TargetCompoundDynamic _TargetUpdate = new TargetCompoundDynamic();
            _TargetUpdate.ChildEntities = _SalesorderDetailArr;
            _TargetUpdate.Entity = _Salesorder;
            CompoundUpdateRequest _Request = new CompoundUpdateRequest();
            _Request.Target = _TargetUpdate;
            CompoundUpdateResponse _Response = (CompoundUpdateResponse)_iService.Execute(_Request);

2 Comments

Filed under MS CRM 4.0, Workflow & Plugin Development

Customization Import from CRM online to Onpremise

Today I tried to import my customization.xml from CRM online to onpremise and I got error

 “Either the file could not be uploaded, or this is not a valid Customization file.”

I was surprised. I tried to import the same file to my CRM online environment again and it imported successfully. So my first thought was to enable trace and check for log files, I got one log file. I check that log file using CRM 4.0 Trace Log Viewer and I found an exception message

“The element ‘savedquery’ has invalid child element ‘visualizations’. List of possible elements expected:’Description,columnsetxml’.”

So “Visualization” was the main culprit here. In CRM online visualization represents to Charts, so a visualization tags is added under savedquery node. So I modified my customization xml file in visual studio and deleted all visualization tags and then imported my customization file and it worked like a charm.

Cheer.

Leave a comment

Filed under MS CRM 4.0

Close Activity based on Due Date using workflow


 

I got one requirement from my client where we need to complete Email activity based on it’s Due date. so I have to check if current date is equal to email’s due date then close email activity. So I created a workflow to implement this. Here are the steps to create workflow

1.       Create new workflow select Entity as Email, Give some name to workflow like “Close Email”, Select new Blank workflow.

2.       Select Run when record is created.

3.       Select “Wait Condition”

 

Timeout until Email:Due Date

5.       Select Row under and add new step “Change record status” and set email status as completed.

6.       It should look like as below.

                                           

 

7.       Publish your workflow and create Email record and set due date. workflow will close email activity based on it’s due date.

 

Cheer !!!

Leave a comment

Filed under MS CRM 4.0, Workflow & Plugin Development