Monday, January 23, 2012

Operation is not valid due to the current state of the object. - asp.net C# listview

If your website receives the error "Operation is not valid due to the current state of the object.", it is due to your list view returning a large set of data that exceeds the threshold.

This issue is due to a Microsoft security update on 1/17/2012.

Resolution(s) (do one of the following):
1. Add pagination to your list view
2. Add filtering so the list view returns less rows
3. Update your web.config file to contain a new appSettings key/value:

Saturday, March 19, 2011

CRM 2011 Retrieve Request - Retrieve Entity Record from Related Entity

With the new release of MS CRM 2011, there are new and better ways to peform some client side scripting.

Below is an example on how to retrieve data from the account entity on the contact form.



function RetrieveAccount(oAccount)
{
var oReq = getXMLHttpRequest();
if (oReq != null)
{
if (oAccount[0] != null)
{
oReq.open("GET", Xrm.Page.context.getServerUrl() +"/XRMServices/2011/OrganizationData.svc/AccountSet?$filter=AccountId%20eq%20(guid'" + oAccount[0].id + "')&$select=Name,AccountId,Telephone1", true);

oReq.onreadystatechange = function () { DisplayAccountData(oReq) };
oReq.send();
}
}
else
{
alert('not supported');
}
}

function getXMLHttpRequest () {
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest;
}
else {
try
{ return new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
catch (ex) {
return null;
}
}
}

function DisplayAccountData (oReq)
{
if (oReq.readyState == 4 /* complete */)
{
if (oReq.status == 200)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(oReq.responseText);
alert('Name: ' + xmlDoc.selectSingleNode("//d:Name").text);
alert('Guid: ' + xmlDoc.selectSingleNode("//d:AccountId").text);
alert('Phone: ' + xmlDoc.selectSingleNode("//d:Telephone1").text);
}
}
}



The first function receives account object then creates an XmlHttpRequest. Next is the retrieve method:
oReq.open("GET", Xrm.Page.context.getServerUrl() +"/XRMServices/2011/OrganizationData.svc/AccountSet?$filter=AccountId%20eq%20(guid'" + oAccount[0].id + "')&$select=Name,AccountId,Telephone1", true);
This code uses the "AccountSet" and the query string keys filter and select. We retrieve using the AccountId and return the attributes Name, AccountId, and Telephone1. A SQL query would look like this SELECT Name, AccountId, Telephone FROM Account WHERE AccountId = '[account id value here]'. You can also retrieve on other attributes like Name. Example: $filter=Name%20eq%20'XYZ Company'

The rest of the code waits for the form to load and then uses the returned xml to get the attributes and display each value in alerts.

Now to get it working.



  1. We need to create a javascript file that we will use to upload when creating our library. Copy the code above and save to a file called RetrieveAccount_jscript.js (you can name it differently if you prefer).


  2. We will need to create a library in the Web Resouce. Go to Settings >> Customizations >> Customize the System, then click on the Web Resources left nav link. Click New, which will open a window to enter the following:

    • Name: new_retrieverequest
    • Display Name: Retrieve Request
    • Description: Retrieve account information using the account object parameter.
    • Type: select Script (JScript)
    • Language: English
    • Upload File: RetrieveAccount_jscript.js
  3. Open the Conact Customizable Entity. Open the Main form. Click on Form Properties.

  4. Add the new_retrieverequest library.
  5. Below, the Library section, add the Event Handler with Control=Form and Event=OnLoad.
  6. Add the Event Handler by selecting the libary new_retrieverequest and enter the function name RetrieveAccount. Make sure Enabled is checked.
  7. Next we need to fill out the parameter section. Uncheck the pass context parameter. Enter the following as the parameter to pass to the function: crmForm.parentcustomerid.DataValue.

Click OK on the windows, Save the entity, and Publish. Now open a contact record that has a related parent (which contains a main number). You will receive 3 alert windows displaying the name, guid, and a phone number.


Wednesday, March 2, 2011

Crm 4.0 Workflows Not Running Resolution

First, verify that the Microsoft CRM Asynchronous Processing Service is running. If not start it and workflows should work now.

If it is running, verify that the following query returns the correct server name (from the MSCRM_Config database).

SELECT ColumnName, NVarCharColumn FROM DeploymentProperties WHERE ColumnName in ('ADSdkRootDomain', 'ADWebApplicationRootDomain', 'AsyncSdkRootDomain')

If any are incorrect run the update to set the correct server name in the NVarCharColumn using the ColumnName as the WHERE parameter like so:

UPDATE DeploymentProperties SET NVarCharColumn = 'crmservername' WHERE ColumnName = 'ADSdkRootDomain'

Once you update, restart the Asynch service and IIS.

Monday, February 28, 2011

CRM Print Error: Unable to Load Client Print Control

SQL Server Reporting Services uses an ActiveX Print control to control the print functions in Windows Internet Explorer, this problem may occur if the ActiveX components are not installed.

Try to check the following setps:



  1. Start Windows Internet Explorer.
  2. On the Tools menu, click Internet Options.
  3. On the Security tab, click Local Intranet, and then click Sites
  4. Click Advanced.
  5. Type the URL for the computer that is running Microsoft Dynamics CRM server in the Add this website to the zone box, and then click Add.
  6. Type the URL for the computer that is running Microsoft SQL Server Reporting Services in the Add this website to the zone box, and then click Add.
  7. Click Close to close the Local Intranet dialog box, and then click OK.
  8. On the Security tab, click Custom Level.
  9. Click Enable for each component that is listed under ActiveX controls and plugins.
  10. Click OK to close the Internet Options dialog box.
  11. Exit Windows Internet Explorer, and then start Microsoft Dynamics CRM 3.0.
  12. Try printing the report.

Monday, January 31, 2011

CRM 4.0: Phone Call Entity - Populate Phone Number

Use the code below to populate the phone number field on a phone call record from a lead or contact (regarding object). Also, you can populate the memo/description field to contain all available numbers (home, business, and/or mobile).



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Populate Phone Number Field - by LBMC, Josh Yockey//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(crmForm.FormType == 1 && crmForm.all.regardingobjectid.DataValue != null
&& (crmForm.all.regardingobjectid.DataValue[0].typename == "lead" || crmForm.all.regardingobjectid.DataValue[0].typename == "contact"))
{
var xml = "" +
"" +
"" +
GenerateAuthenticationHeader() +" " +
" " +
" crmForm.all.regardingobjectid.DataValue[0].typename" +
" "+ crmForm.all.regardingobjectid.DataValue[0].id + "" +
" " +
" " +
" telephone2" +
" mobilephone" +
" telephone1" +
"
" +
"
" +
"
" +
"
" +
"
" +
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;

var home = "";
var mobile = "";
var business = "";
var desc = "";
crmForm.all.phonenumber.DataValue = "";

var node = resultXml.selectSingleNode("//q1:telephone2");
if (node != null)
home = resultXml.selectSingleNode("//q1:telephone2").text;

node = resultXml.selectSingleNode("//q1:mobilephone");
if (node != null)
mobile = resultXml.selectSingleNode("//q1:mobilephone").text;

node = resultXml.selectSingleNode("//q1:telephone1");
if (node != null)
business = resultXml.selectSingleNode("//q1:telephone1").text;

if (home.length > 0)
{
crmForm.all.phonenumber.DataValue = home;
desc += "\nHome: " + home;
}
if (mobile.length > 0)
{
if (crmForm.all.phonenumber.DataValue == null || crmForm.all.phonenumber.DataValue.length == 0)
{
crmForm.all.phonenumber.DataValue = mobile;
}
desc += "\nMobile: " + mobile;
}
if (business.length > 0)
{
if (crmForm.all.phonenumber.DataValue == null || crmForm.all.phonenumber.DataValue.length == 0)
{
crmForm.all.phonenumber.DataValue = business;
}
desc += "\nBusiness: " + business;
}

crmForm.all.description.DataValue = desc;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Sunday, October 3, 2010

Compilation Error or Web.config File is Missing - ReflectedSchemas

Recently while writing a program for a friend using Visual Studio 10 Express, all my web pages had the following error on each control:

Element '[control type]' is not a known element. This can occur if there is a compilation error in the web site, or the web.config file is missing

I found that if you delete the files from the following folder, it should solve your problem:
C:\Users\JoshuaYockey\AppData\Roaming\Microsoft\Visual Studio\10.0\ReflectedSchemas
or if you are using Express:
C:\Users\JoshuaYockey\AppData\Roaming\Microsoft\VWDExpress\10.0\ReflectedSchemas

Hope this helps others.

Wednesday, September 22, 2010

Remove Associated Buttons (Add Existing xxxxx to this record)

I recently had a request to remove the "Add Existing [entity name] to this record" button from the associated view for a client.

The below link is a great post on how to do this:

MSCRM 4 - Remove 'Add Existing xxxxx to this record' button by Dave Hawes

The only modification I made to this code was to use
liElements[i].outerHTML='<SPAN></SPAN>'; 

instead of
liElements[i].style.display = 'none';


My next post will discuss how to change the name of these associated buttons.