Answered by:
check if id already exists based in other form - Javascript CRM 4.0

Question
-
Hi guys,
I'm a new javascript dev. and I don't know how to check (at OnSave) if a field equipment id on contract detail form already exists for a contractid.
I've trying something like this:
var equipm = crmForm.all.wttl_baseinstaladaid.DataValue[0].id; //lookup field var contract = crmForm.all.contractid.DataValue; if(contract, equipm) { alert('equipment id already exists for this contract'); event.returnValue = false; event.cancelBubble = true; return false; }
However, I know that this condition is based on a method. But i don't have code access.
For this case, can i use fetchxml or just a trigger?
Thanks.
Btw, sorry about the bad english.
Wednesday, February 12, 2014 12:44 AM
Answers
-
Yeah, it works.
Now, It's retrieving me another error.
This is the results:
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/XML Schema\'> <soap:Header> <CrmAuthenticationToken xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\"> <AuthenticationType xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">0</AuthenticationType> <CrmTicket xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\"></CrmTicket> <OrganizationName xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">Wittel</OrganizationName> <CallerId xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">00000000-0000-0000-0000-000000000000</CallerId> </CrmAuthenticationToken> </soap:Header> <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>contractdetail</q1:EntityName> <q1:ColumnSet xsi:type=\'q1:ColumnSet\'> <q1:Attributes> <q1:Attribute>wttl_baseinstaladaid</q1:Attribute> </q1:Attributes> </q1:ColumnSet> <q1:Distinct>false</q1:Distinct> <q1:Criteria> <q1:FilterOperator>And</q1:FilterOperator> <q1:Conditions> <q1:Condition> <q1:AttributeName>DeletionStateCode</q1:AttributeName> <q1:Operator>ne</q1:Operator> <q1:Values> <q1:Value xsi:type=\'xsd:string\'>2</q1:Value> </q1:Values> </q1:Condition> <q1:Condition> <q1:AttributeName>wttl_baseinstaladaid</q1:AttributeName> <q1:Operator>Like</q1:Operator> <q1:Values> <q1:Value xsi:type=\'xsd:string\'>{AB29CC09-71FC-DE11-91DD-00155D023601}</q1:Value> </q1:Values> </q1:Condition> <q1:Condition> <q1:AttributeName>contractid</q1:AttributeName> <q1:Operator>Like</q1:Operator> <q1:Values> <q1:Value xsi:type=\'xsd:string\'>{78CE2E9E-4D92-E311-816B-000C29A8E423}</q1:Value> </q1:Values> </q1:Condition> </q1:Conditions> </q1:Criteria> </query> </RetrieveMultiple> </soap:Body> </soap:Envelope>"
And the resultXml =
"<?xml version=\"1.0\"?>\r\n<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\"> <soap:Body> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>Server was unable to process request.</faultstring> <detail> <error>\r\n\t\t\t\t\t <code>0x80040216</code>\r\n\t\t\t\t\t <description>An unexpected error occurred.</description>\r\n\t\t\t\t\t <type>Platform</type>\r\n\t\t\t\t </error> </detail> </soap:Fault> </soap:Body> </soap:Envelope>\r\n"
Can you see something wrong?
This is my actual code:
var equip = crmForm.all.wttl_baseinstaladaid.DataValue[0].id; var contract = crmForm.all.contractid.DataValue; 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/XML Schema'>"+ 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>contractdetail</q1:EntityName>"+ "<q1:ColumnSet xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute>wttl_baseinstaladaid</q1:Attribute>"+ "</q1:Attributes>"+ "</q1:ColumnSet>"+ "<q1:Distinct>false</q1:Distinct>"+ "<q1:Criteria>"+ "<q1:FilterOperator>And</q1:FilterOperator>"+ "<q1:Conditions>"+ "<q1:Condition>"+ "<q1:AttributeName>DeletionStateCode</q1:AttributeName>"+ "<q1:Operator>ne</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+2+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "<q1:Condition>"+ "<q1:AttributeName>wttl_baseinstaladaid</q1:AttributeName>"+ "<q1:Operator>Like</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+equip+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "<q1:Condition>"+ "<q1:AttributeName>contractid</q1:AttributeName>"+ "<q1:Operator>Like</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+contract+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "</q1:Conditions>"+ "</q1:Criteria>"+ "</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"); xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xHReq.setRequestHeader("Content-Length", xml.length); xHReq.send(xml); var resultXml = xHReq.responseXML; var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } else { var results = resultXml.getElementsByTagName('BusinessEntity'); if (results.length>0) { Alert('equipment id already exists for this contract'); } }
Thanks.
- Marked as answer by tpugli Friday, February 14, 2014 2:04 PM
Thursday, February 13, 2014 6:04 PM
All replies
-
Yes, sounds like you need to use fetch xml to query and check if the record already exists.
I recommend using XrmSvcToolkit to query. http://xrmsvctoolkit.codeplex.com/ Add XrmSvcToolkit to your form and then you can query like so:
XrmSvcToolkit.fetch({ fetchXml: fetchXml, async: false, successCallback: function (result) { }, errorCallback: function (error) { } });
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
CRM 2011 JavaScript Model Generator - CRM 2011 Appender for log4netWednesday, February 12, 2014 2:58 AM -
Hey, thanks for reply.
But, to use this library i'll need to install the dev. tool kit right?
Wednesday, February 12, 2014 12:05 PM -
Yes, you need to xrmsvctoolkit for above solution, and if you can write server side code you could write create/update plugin to validate the same as well.
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Wednesday, February 12, 2014 12:41 PMModerator -
Right, Just another question. is this library works for crm 4.0? didn't find any reference about.
Wednesday, February 12, 2014 1:20 PM -
Hi,
No,It is available only from crm 2011.
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Wednesday, February 12, 2014 1:38 PMModerator -
So this solution still doesn't work for me.
tks.
Wednesday, February 12, 2014 1:43 PM -
Check this for CRM 4.0: http://crmtoolkit.codeplex.com/
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Wednesday, February 12, 2014 1:47 PMModerator -
Hi guys, I need some help.
I try to make a code just with retrieve multiple method (http://msdn.microsoft.com/en-us/library/cc677076.aspx)
then, I've this code:
var equip = crmForm.all.wttl_baseinstaladaid.DataValue[0].id; var contract = crmForm.all.contractid.DataValue; 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/XML Schema'>"+ 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' aggregate='true'>"+ "<q1:EntityName>contractDetail</q1:EntityName>"+ "<q1:ColumnSet xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute aggregate='countcolumn' alias='equip_count'>wttl_baseinstaladaid</q1:Attribute>"+ "</q1:Attributes>"+ "</q1:ColumnSet>"+ "<q1:Distinct>false</q1:Distinct>"+ "<q1:Criteria>"+ "<q1:FilterOperator>And</q1:FilterOperator>"+ "<q1:Conditions>"+ "<q1:Condition>"+ "<q1:AttributeName >wttl_baseinstaladaid</q1:AttributeName>"+ "<q1:Operator>Equal</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+equip+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "<q1:Condition>"+ "<q1:AttributeName>contractid</q1:AttributeName>"+ "<q1:Operator>Equal</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+contract+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "<q1:Condition>"+ "<q1:AttributeName>DeletionStateCode</q1:AttributeName>"+ "<q1:Operator>ne</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+'2'+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "</q1:Conditions>"+ "</q1:Criteria>"+ "</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"); 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); } // Display the retrieved value. else { alert(resultXml.selectSingleNode("q1:wttl_baseinstaladaid").nodeTypedValue); }
but this code brings me this error at resultXml:
"<?xml version=\"1.0\"?>\r\n<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\"> <soap:Body> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>Server was unable to process request.</faultstring> <detail> <error>\r\n\t\t\t\t\t <code>0x80040216</code> \r\n\t\t\t\t\t<description>An unexpected error occurred.</description> \r\n\t\t\t\t\t<type>Platform</type>\r\n\t\t\t\t</error> </detail> </soap:Fault> </soap:Body> </soap:Envelope>\r\n"
Any idea about what this error means?
tks.
Wednesday, February 12, 2014 7:11 PM -
what is the datatype of contract ?? it seems it's a lookup ??
so you need to use the same, then try to debug your code and check your request if it is correct or not.
var contract = crmForm.all.contractid.DataValue[0].id
Check how to debug
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Thursday, February 13, 2014 5:54 AMModerator -
Contractid isn't a lookup field in this case and at debugger i can see the value. So it's ok.
I believe that this problem is in aggregation. I remove it and the code works.
I want to do a count of wttl_baseinstaladaid by the number of contraid to see if the value already exists to this contract in contractdetail.
In this structure I don't know how.
Can someone help me?
tks again.
Thursday, February 13, 2014 2:12 PM -
If you just need to check resultset could you should be able to do it like below
if (errorCount != 0) { var msg = resultXml.selectSingleNode('description').nodeTypedValue; alert(msg); }
else{var results = resultXml.getElementsByTagName('BusinessEntity'); if (results.length>0){//it means record already exists}
}
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Thursday, February 13, 2014 4:15 PMModerator -
Yeah, it works.
Now, It's retrieving me another error.
This is the results:
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/XML Schema\'> <soap:Header> <CrmAuthenticationToken xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\"> <AuthenticationType xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">0</AuthenticationType> <CrmTicket xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\"></CrmTicket> <OrganizationName xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">Wittel</OrganizationName> <CallerId xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">00000000-0000-0000-0000-000000000000</CallerId> </CrmAuthenticationToken> </soap:Header> <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>contractdetail</q1:EntityName> <q1:ColumnSet xsi:type=\'q1:ColumnSet\'> <q1:Attributes> <q1:Attribute>wttl_baseinstaladaid</q1:Attribute> </q1:Attributes> </q1:ColumnSet> <q1:Distinct>false</q1:Distinct> <q1:Criteria> <q1:FilterOperator>And</q1:FilterOperator> <q1:Conditions> <q1:Condition> <q1:AttributeName>DeletionStateCode</q1:AttributeName> <q1:Operator>ne</q1:Operator> <q1:Values> <q1:Value xsi:type=\'xsd:string\'>2</q1:Value> </q1:Values> </q1:Condition> <q1:Condition> <q1:AttributeName>wttl_baseinstaladaid</q1:AttributeName> <q1:Operator>Like</q1:Operator> <q1:Values> <q1:Value xsi:type=\'xsd:string\'>{AB29CC09-71FC-DE11-91DD-00155D023601}</q1:Value> </q1:Values> </q1:Condition> <q1:Condition> <q1:AttributeName>contractid</q1:AttributeName> <q1:Operator>Like</q1:Operator> <q1:Values> <q1:Value xsi:type=\'xsd:string\'>{78CE2E9E-4D92-E311-816B-000C29A8E423}</q1:Value> </q1:Values> </q1:Condition> </q1:Conditions> </q1:Criteria> </query> </RetrieveMultiple> </soap:Body> </soap:Envelope>"
And the resultXml =
"<?xml version=\"1.0\"?>\r\n<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\"> <soap:Body> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>Server was unable to process request.</faultstring> <detail> <error>\r\n\t\t\t\t\t <code>0x80040216</code>\r\n\t\t\t\t\t <description>An unexpected error occurred.</description>\r\n\t\t\t\t\t <type>Platform</type>\r\n\t\t\t\t </error> </detail> </soap:Fault> </soap:Body> </soap:Envelope>\r\n"
Can you see something wrong?
This is my actual code:
var equip = crmForm.all.wttl_baseinstaladaid.DataValue[0].id; var contract = crmForm.all.contractid.DataValue; 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/XML Schema'>"+ 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>contractdetail</q1:EntityName>"+ "<q1:ColumnSet xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute>wttl_baseinstaladaid</q1:Attribute>"+ "</q1:Attributes>"+ "</q1:ColumnSet>"+ "<q1:Distinct>false</q1:Distinct>"+ "<q1:Criteria>"+ "<q1:FilterOperator>And</q1:FilterOperator>"+ "<q1:Conditions>"+ "<q1:Condition>"+ "<q1:AttributeName>DeletionStateCode</q1:AttributeName>"+ "<q1:Operator>ne</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+2+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "<q1:Condition>"+ "<q1:AttributeName>wttl_baseinstaladaid</q1:AttributeName>"+ "<q1:Operator>Like</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+equip+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "<q1:Condition>"+ "<q1:AttributeName>contractid</q1:AttributeName>"+ "<q1:Operator>Like</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+contract+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "</q1:Conditions>"+ "</q1:Criteria>"+ "</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"); xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xHReq.setRequestHeader("Content-Length", xml.length); xHReq.send(xml); var resultXml = xHReq.responseXML; var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } else { var results = resultXml.getElementsByTagName('BusinessEntity'); if (results.length>0) { Alert('equipment id already exists for this contract'); } }
Thanks.
- Marked as answer by tpugli Friday, February 14, 2014 2:04 PM
Thursday, February 13, 2014 6:04 PM -
Hi Guys, tks for your colaboration.
I found a better solution.
crmForm.validaEquipContrato=function() { var equip = crmForm.all.wttl_baseinstaladaid.DataValue[0].id; var contractid = crmForm.all.contractid.DataValue; 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>contractdetail</q1:EntityName>"+ "<q1:ColumnSet xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute>wttl_baseinstaladaid</q1:Attribute>"+ "</q1:Attributes>"+ "</q1:ColumnSet>"+ "<q1:Distinct>false</q1:Distinct>"+ "<q1:Criteria>"+ "<q1:FilterOperator>And</q1:FilterOperator>"+ "<q1:Conditions>"+ "<q1:Condition>"+ "<q1:AttributeName>contractid</q1:AttributeName>"+ "<q1:Operator>Equal</q1:Operator>"+ "<q1:Values>"+ "<q1:Value xsi:type='xsd:string'>"+contractid+"</q1:Value>"+ "</q1:Values>"+ "</q1:Condition>"+ "</q1:Conditions>"+ "</q1:Criteria>"+ "</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"); 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; var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } else { var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities"); var nodesXml = entityNode.selectNodes("BusinessEntity"); if(nodesXml.length>0) { for(var i=0;i<nodesXml.length;i++) { if(nodesXml[i].selectSingleNode("q1:wttl_baseinstaladaid").text == crmForm.all.wttl_baseinstaladaid.DataValue[0].id) { alert('Equipment already exists in this constract'); crmForm.all.wttl_baseinstaladaid.DataValue = null; crmForm.all.wttl_baseinstaladaid.SetFocus(); event.returnValue = false; event.cancelBubble = true; return false; } } } } }
Friday, February 14, 2014 2:06 PM