Answered by:
Execute method- Assign Request - Javascript

Question
-
Hi,
I am trying to execute an Assign Request using script. I am framing my input xml wrongly. Can anybody help me to correct it.
It says "unexpected error occured.
var User="User";
var PrincipalId="5AB7EF25-BA14-E011-8EF1-001E902341EC";
var EntityId = "BD3D383D-0317-E011-8EF1-001E902341EC";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>"+
"<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<Request xsi:type='AssignRequest'>"+
"<Assignee>"+
"<Type>"+User+"</Type>"+
"<PrincipalId>"+ PrincipalId+"</PrincipalId>"+
"</Assignee>"+
"<Target TargetOwnedAccount>"+
"<EntityId>"+ EntityId+"</EntityId>"+
"</Target>"+
"</Request>"+
"</Execute>"+
"</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/Execute");
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;
alert(xml);
alert(resultXml.xml);
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
alert(errorCount);
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
soumyaFriday, January 14, 2011 11:05 AM
Answers
-
Try this
var header = GenerateAuthenticationHeader();
var userid = "5AB7EF25-BA14-E011-8EF1-001E902341EC";var recordid = "BD3D383D-0317-E011-8EF1-001E902341EC";var target = "TargetOwnedAccount";
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\">" +header +" <soap:Body>" +" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +" <Request xsi:type=\"AssignRequest\">" +" <Target xsi:type=\""+ target +"\">" +" <EntityId>"+ recordid +"</EntityId>" +" </Target>" +" <Assignee>" +" <PrincipalId xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">"+ userid +"</PrincipalId>" +" <Type xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">User</Type>" +" </Assignee>" +" </Request>" +" </Execute>" +" </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/Execute");xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");xmlHttpRequest.setRequestHeader("Content-Length", xml.length);xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;- Proposed as answer by Andrii ButenkoMVP, Moderator Friday, January 14, 2011 9:51 PM
- Marked as answer by Soumya Sasidharan Saturday, January 15, 2011 1:31 PM
Friday, January 14, 2011 1:08 PM
All replies
-
Try this
var header = GenerateAuthenticationHeader();
var userid = "5AB7EF25-BA14-E011-8EF1-001E902341EC";var recordid = "BD3D383D-0317-E011-8EF1-001E902341EC";var target = "TargetOwnedAccount";
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\">" +header +" <soap:Body>" +" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +" <Request xsi:type=\"AssignRequest\">" +" <Target xsi:type=\""+ target +"\">" +" <EntityId>"+ recordid +"</EntityId>" +" </Target>" +" <Assignee>" +" <PrincipalId xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">"+ userid +"</PrincipalId>" +" <Type xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">User</Type>" +" </Assignee>" +" </Request>" +" </Execute>" +" </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/Execute");xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");xmlHttpRequest.setRequestHeader("Content-Length", xml.length);xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;- Proposed as answer by Andrii ButenkoMVP, Moderator Friday, January 14, 2011 9:51 PM
- Marked as answer by Soumya Sasidharan Saturday, January 15, 2011 1:31 PM
Friday, January 14, 2011 1:08 PM -
Thankyou.....
soumyaSaturday, January 15, 2011 1:33 PM