I am reconfiguring an application that we had running in CRM 4.0 to run in CRM 2011. It was previously called from a toolbar button using javascript.
I have transferred the javascript to a web resource and reconfigured the ribbon to hold the button and call the required function within the library.
When testing this however, I am being prompted for username and password which when entered 3 or so times returns the error "'null' is null or not an object".
I am not sure why I am getting prompted for credentials when this did not happen in CRM 4.0.
Any ideas what may be causing this?
The javascript is below:
try
{
var ADD_LETTER='1';
var SAVE_DOC_IN_CRM='1';
var STORE_TO_PRINT='1';
var SEND_EMAIL='1';
var SHOW_PARAGRAPHS='1';
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\'>'+GenerateAuthenticationHeader() +' <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>systemuser</q1:EntityName>' +' <q1:ColumnSet xsi:type=\'q1:ColumnSet\'>' +' <q1:Attributes>' +' <q1:Attribute>systemuserid</q1:Attribute>' +' </q1:Attributes>' +' </q1:ColumnSet>' +' <q1:Distinct>false</q1:Distinct>' +' <q1:Criteria>' +' <q1:FilterOperator>And</q1:FilterOperator>' +' <q1:Conditions>' +' <q1:Condition>' +' <q1:AttributeName>systemuserid</q1:AttributeName>' +' <q1:Operator>EqualUserId</q1:Operator>' +' </q1:Condition>' +' </q1:Conditions>' +' </q1:Criteria>' +' </query>' +' </RetrieveMultiple>' +' </soap:Body>' +'</soap:Envelope>' +'';
var xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
xmlHttpRequest.Open('POST', '/mscrmservices/2007/CrmService.asmx', false);
xmlHttpRequest.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple');
xmlHttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlHttpRequest.setRequestHeader('Content-Length', xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var entityNode = resultXml.selectSingleNode('//RetrieveMultipleResult/BusinessEntities/BusinessEntity');
var useridNode = entityNode.selectSingleNode('q1:systemuserid');
var sUserId = (useridNode == null) ? '' : useridNode.text;
var sGUID = crmForm.ObjectId;
var sEntity = crmForm.ObjectTypeName;
var sURL = '/ISV/Mergedabc/Mergedabc.aspx?org=' + ORG_UNIQUE_NAME + '&guid=' + sGUID + '&ety=' + sEntity + '&userid=' + sUserId + '&indid=' + sGUID + '&indtype=' + crmForm.ObjectTypeCode + '&indtypename=' + sEntity + '&addletter=' + ADD_LETTER + '&docincrm=' + SAVE_DOC_IN_CRM + '&storetoprint=' + STORE_TO_PRINT + '&emaildoc=' + SEND_EMAIL + '&showparas=' + SHOW_PARAGRAPHS;
var objRet = window.showModalDialog(prependOrgName(sURL));
if(objRet != null)
{
if (objRet.length > 0)
{
var o = objRet[0];
if (o.ret == true)
{
alert('Merge Completed.');
}
else {
alert('Unable to merge document.');
}
}
else
{
alert('No merge information returned.');
}
}
}
catch (e)
{
alert(e.message);
}
It looks as though this is happening when it tries to call the CrmService and is causing a 401 error.
Any suggestions on how to fix this will be appreciated,
Thanks!!
Fixed – the issue was the XML-isation of all the %amp;
%lt;
%gt;
instead of %
, <
and >
in the SOAP call.