Hi I want on filling the comment card lookup, fetch (get) fields from comment card to case:
Guest, Incident Type (from CC Type), and date of incident (from date of visit) .. But Its giving an error any help ?
// ----- Start Of Script : Fetch Guest, Incident type and date of incident from commentcard
Fetch Area Code from Area
function FetchCommentCard ()
{
var CC= Xrm.Page.getAttribute("new_commentcard").getValue();
if (CC != null && CC != "")
{
var Guest;
var IncidentType;
var dateOfIncident;
var serverUrl = Xrm.Page.context.getClientUrl();
if (serverUrl.match(/\/$/))
{
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}
// To be updated as required
var fetchXml = "<fetch mapping='logical' version='1.0'>"
+ "<entity name='new_commentcard'>"
+ "<attribute name='new_commentcardid'/>"
+ "<attribute name='new_cctype'/>"
+ "<attribute name='new_dateofvisit'/>"
+ "<filter>"
+ "<condition attribute='new_commentcard' operator='eq' value='" + CC[0].id + "'/>"
+ "</filter>"
+ "</entity>"
+ "</fetch>";
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +"<soapenv:Envelope xmlns:soapenv=\"schemas.xmlsoap.org/.../envelope\">" +"<soapenv:Body>" +"<RetrieveMultiple xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">" +"<query i:type=\"a:FetchExpression\" xmlns:a=\"schemas.microsoft.com/.../Contracts\">" +"<a:Query>" + fetchXml.replace(/\&/g, '&' + 'amp;').replace(/</g, '&' + 'lt;').replace(/>/g, '&' + 'gt;').replace(/\'/g, '&' + 'apos;').replace(/\"/g, '&' + 'quot;') + "</a:Query>" +"</query>" +"</RetrieveMultiple>" +"</soapenv:Body>" +"</soapenv:Envelope>";
var xmlHttpRequest;
var doc;
var result;
if (window.XMLHttpRequest)
{
// code for IE7, IE8, IE9 , IE10 , Firefox, Chrome, Opera, Safari
xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", serverUrl + "/XRMServices/2011/Organization.svc/web", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
result = xmlHttpRequest.responseXML.xml;
}
else
{
// code for IE6, IE5
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
result = xmlHttpRequest.responseXML.xml;
}
if (window.DOMParser)
{
parser = new DOMParser();
doc = parser.parseFromString(xmlHttpRequest.responseText, "text/xml");
}
// Internet Explorer
else
{
doc = new ActiveXObject("MSXML2.DOMDocument");
doc.async = false;
doc.loadXML(result);
}
if (navigator.userAgent.toLowerCase().indexOf("chrome") > - 1)
{
var vals = doc.getElementsByTagName("KeyValuePairOfstringanyType");
for (var j = 0; j < vals.length; j ++ )
{
if(vals[j].getElementsByTagName("key")[0].firstChild.nodeValue == "new_commentcard")
{
CC = vals[j].getElementsByTagName("value")[0].textContent;
Xrm.Page.getAttribute("new_commentcardid").setValue(CC);
Xrm.Page.getAttribute("new_cctype").setValue(CC);
Xrm.Page.getAttribute("new_dateofvisit").setValue(CC);
}
}
}
else
{
var vals = doc.getElementsByTagName("a:KeyValuePairOfstringanyType");
for (var j = 0; j < vals.length; j ++ )
{
if(vals[j].getElementsByTagName("b:key")[0].firstChild.nodeValue == "new_commentcard")
{
CC = vals[j].getElementsByTagName("b:value")[0].textContent;
Xrm.Page.getAttribute("new_cctype").setValue(CC);
Xrm.Page.getAttribute("new_commentcardid").setValue(CC);
Xrm.Page.getAttribute("new_cctype").setValue(CC);
}
}
}
}
}
// ----- End Of Script