Answered by:
R4: How to use RetrieveMultiple to retrieve only active records using Jscript?

Question
-
Hi All,
Whenever I run my retrievemultiple Jscript, it also returns Deactivated records. Can I filter them just to retrieve active record? Please find the code below:
// Define the SOAP XML to access Microsoft Dynamics CRM Web service.
var sXML = "<?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\">" +
sAuthenticationHeader+
"<soap:Body>" +// Specify the RetrieveMultiple message.
"<RetrieveMultiple xmlns="+
"\"http://schemas.microsoft.com/crm/2007/WebServices\">" +// Specify that this is a QueryByAttribute query.
"<query xmlns:q1="+
"\"http://schemas.microsoft.com/crm/2006/Query\" "+
"xsi:type=\"q1:QueryByAttribute\">" +// Query the Revenue Projection Entity
"<q1:EntityName>new_revenueprojection</q1:EntityName>" +// Set the columns you want to return.
"<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
"<q1:Attributes>" +
"<q1:Attribute>new_janrev</q1:Attribute>" +
"<q1:Attribute>new_febrev</q1:Attribute>" +
"<q1:Attribute>new_marrev</q1:Attribute>" +
"<q1:Attribute>new_aprrev</q1:Attribute>" +
"<q1:Attribute>new_mayrev</q1:Attribute>" +
"<q1:Attribute>new_junrev</q1:Attribute>" +
"<q1:Attribute>new_julrev</q1:Attribute>" +
"<q1:Attribute>new_augrev</q1:Attribute>" +
"<q1:Attribute>new_seprev</q1:Attribute>" +
"<q1:Attribute>new_octrev</q1:Attribute>" +
"<q1:Attribute>new_novrev</q1:Attribute>" +
"<q1:Attribute>new_decrev</q1:Attribute>" +
"</q1:Attributes>" +
"</q1:ColumnSet>" +// Specify the attribute that you are querying on.
"<q1:Attributes>" +
"<q1:Attribute>new_revenueprojectionidid</q1:Attribute>" +
"</q1:Attributes>" +// Set the value of the attribute using the OptyId
"<q1:Values>" +
"<q1:Value xsi:type=\"xsd:string\">"+
sOptyId+
"</q1:Value>" +
"</q1:Values>" +
"</query>" +
"</RetrieveMultiple>" +
"</soap:Body>" +
"</soap:Envelope>";// Create an instance of an XMLHTTP object.
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");// Configure the XMLHttp object for the Microsoft CRM Web services.
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", sXML.length);// Send the XMLHttp request.
xmlHttpRequest.send(sXML);// Capture the XMLHttp response in XML format.
sResultXML = xmlHttpRequest.responseXML;// Create an XML document that you can parse.
oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false;// Load the document that has the results.
oXmlDoc.loadXML(sResultXML.xml);Thursday, April 16, 2009 11:37 AM
Answers
-
Hi Prafulla,
You need to add one more condition attribute to check for statecode having value as 0 i.e active record.
Regards,
Nishant Rana
http://nishantrana.wordpress.com- Marked as answer by JuergenBeckModerator Wednesday, April 22, 2009 8:24 AM
Thursday, April 16, 2009 12:14 PM -
Hi Prafulla,
it seems you create the JScript on your own without an generator.
I can really recommend this article which comes with a free tool from stunnware
"Using CRM 4.0 Web Services in client-side JavaScript"
http://www.stunnware.com/crm2/topic.aspx?id=JSWebService2
Just create your .NET-code and you get the appropriate JScript.
In the .NET you just have to create a filter for the statecode column for the value "0" for getting the active rows.
Best regards,
Jürgen
Jürgen Beck
Dipl. Kfm./Wirtschaftsinformatik
MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
Microsoft Certified Business Management Solutions Professional
Microsoft Certified CRM Developer
Microsoft Certified Trainer
ComBeck IT Services & Business Solutions
Microsoft Gold Certified Partner
Microsoft Small Business Specialist
Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors
http://www.combeck.de
- Proposed as answer by JuergenBeckModerator Thursday, April 16, 2009 12:16 PM
- Marked as answer by JuergenBeckModerator Wednesday, April 22, 2009 8:24 AM
Thursday, April 16, 2009 12:16 PMModerator -
Hi,
You can check the state attribute for active/inactive in your filter criteria;
Morten
- Marked as answer by JuergenBeckModerator Wednesday, April 22, 2009 8:24 AM
Thursday, April 16, 2009 12:16 PM
All replies
-
Hi Prafulla,
You need to add one more condition attribute to check for statecode having value as 0 i.e active record.
Regards,
Nishant Rana
http://nishantrana.wordpress.com- Marked as answer by JuergenBeckModerator Wednesday, April 22, 2009 8:24 AM
Thursday, April 16, 2009 12:14 PM -
Hi Prafulla,
it seems you create the JScript on your own without an generator.
I can really recommend this article which comes with a free tool from stunnware
"Using CRM 4.0 Web Services in client-side JavaScript"
http://www.stunnware.com/crm2/topic.aspx?id=JSWebService2
Just create your .NET-code and you get the appropriate JScript.
In the .NET you just have to create a filter for the statecode column for the value "0" for getting the active rows.
Best regards,
Jürgen
Jürgen Beck
Dipl. Kfm./Wirtschaftsinformatik
MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
Microsoft Certified Business Management Solutions Professional
Microsoft Certified CRM Developer
Microsoft Certified Trainer
ComBeck IT Services & Business Solutions
Microsoft Gold Certified Partner
Microsoft Small Business Specialist
Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors
http://www.combeck.de
- Proposed as answer by JuergenBeckModerator Thursday, April 16, 2009 12:16 PM
- Marked as answer by JuergenBeckModerator Wednesday, April 22, 2009 8:24 AM
Thursday, April 16, 2009 12:16 PMModerator -
Hi,
You can check the state attribute for active/inactive in your filter criteria;
Morten
- Marked as answer by JuergenBeckModerator Wednesday, April 22, 2009 8:24 AM
Thursday, April 16, 2009 12:16 PM