Answered by:
Access the account user query (Advanced Find View)

Question
-
Hi,
I want store all user query (advanced find save view) of account in a picklist on a custom entity.
Saturday, February 12, 2011 9:12 AM
Answers
-
That's probably because you're changing the DataValue. If you don't intend to save changes to the "new_accsavedview" field, then write a bit of OnSave event code to Disable the field--at least, I think that'll work (to be honest, I don't think I've ever tried that). When a field is disabled, any changes to the data are ignored by the CRM UI.
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.- Proposed as answer by Jim Glass Jr Tuesday, February 15, 2011 10:12 PM
- Marked as answer by Mohd Shams Friday, February 18, 2011 8:55 AM
Tuesday, February 15, 2011 7:58 PMModerator
All replies
-
Use the SavedQueryBase table to get your views.
Cornel Croitoriu - Senior Software Developer - www.Biz-Forward.comSaturday, February 12, 2011 11:42 AM -
Thanks for ur reply. But SavedQueryBase table gives only system views. My concern is that I want to store all UserQuery. I'm trying write jscript and get the all views. I just want to know how to add in an attribute.
Code:
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">'; fetchXml += '<entity name="userquery">'; fetchXml += '<attribute name="name"/>'; fetchXml += '<attribute name="userqueryid"/>'; fetchXml += '<filter type="and">'; fetchXml += ' <condition attribute="returnedtypecode" operator="eq" value="1"/>'; fetchXml += '</filter>'; fetchXml += '</entity>'; fetchXml += '</fetch>'; Fetch(fetchXml); function Fetch( xml ) { var Xml = "<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\">" Xml += GenerateAuthenticationHeader() Xml += "<soap:Body>"; Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">"; Xml += "<fetchXml>"; Xml += _HtmlEncode(xml); Xml += "</fetchXml>"; Xml += "</Fetch>"; Xml += "</soap:Body>"; Xml += "</soap:Envelope>"; var XmlHttp = CreateXmlHttp(); XmlHttp.open("POST", "http://<servername>:5555/MSCrmServices/2007/CrmService.asmx", false ); XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); XmlHttp.send(Xml); var resultDoc = loadXmlDocument(XmlHttp.responseXML.text); var resultRecords = resultDoc.selectNodes("//name"); var resultlength = resultRecords.length; //Add values into picklist (new_accsavedview) if( resultlength == 1 ) { for (var i=0; i<resultlength; i++) { crmForm.all.new_accsavedview.dataVlaue[i].Text; crmForm.all.new_accsavedview.dataVlaue[i].value; } } }
Saturday, February 12, 2011 12:32 PM -
The return xml looks like:
<resultset morerecords="0" paging-cookie="<cookie page="1"><userqueryid last="{A4D923E8-3107-42E6-B6BC-778FDF255E8E}" first="{0EC8447F-DEDC-DF11-8EAE-00163500CA9E}" /></cookie>"> <result> <name>Accounts with Sharepoint</name> <userqueryid>{0EC8447F-DEDC-DF11-8EAE-00163500CA9E}</userqueryid> </result> <result> <name>My Accounts</name> <userqueryid>{263B41C3-D426-4A3E-BD03-4957D60A4402}</userqueryid> </result> <result> <name>My Address Book Accounts</name> <userqueryid>{A4D923E8-3107-42E6-B6BC-778FDF255E8E}</userqueryid> </result> </resultset>
In order to retrieve the 'name' and 'userqueryid' attributes, you should iterate over the 'result' nodes:
var resultRecords = resultDoc.selectNodes("//result"); for (var i = 0; i < resultRecords.length; i++) { var text = resultRecords[i].selectSingleNode("name").text; var value = resultRecords[i].selectSingleNode("userqueryid").text; crmForm.all.new_accsavedview.AddOption(text, value); }
--pogo (pat)- Proposed as answer by VinothBalasubramanian Monday, February 14, 2011 4:19 AM
Monday, February 14, 2011 12:15 AM -
Hi thnak for reply. Here u passed static value but I need dynamic value. If some one add a new custome views then I have to modify the code. In my system there are 5 view. When I'm trying to add these values into picklis it adds only one(first) view 5 times.
Code:
var AccSavedView = ""; var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">'; fetchXml += '<entity name="userquery">'; fetchXml += '<attribute name="name"/>'; fetchXml += '<attribute name="userqueryid"/>'; fetchXml += '<filter type="and">'; fetchXml += ' <condition attribute="returnedtypecode" operator="eq" value="1"/>'; fetchXml += ' <condition attribute="querytype" operator="eq" value="0"/>'; fetchXml += '</filter>'; fetchXml += '</entity>'; fetchXml += '</fetch>'; Fetch(fetchXml); function Fetch( xml ) { var Xml = "<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\">" Xml += GenerateAuthenticationHeader() Xml += "<soap:Body>"; Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">"; Xml += "<fetchXml>"; Xml += _HtmlEncode(xml); Xml += "</fetchXml>"; Xml += "</Fetch>"; Xml += "</soap:Body>"; Xml += "</soap:Envelope>"; // Prepare the xmlHttpObject and send the request. var XmlHttp = CreateXmlHttp(); XmlHttp.open("POST", "http://devserver:5555/MSCrmServices/2007/CrmService.asmx", false ); XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); XmlHttp.send(Xml); // Capture the result. var resultDoc = loadXmlDocument(XmlHttp.responseXML.text); // Process and display the results. (In order to retrieve the 'name' and 'userqueryid' attributes) var resultRecords = resultDoc.selectNodes("//name"); //var resultRecords1 = resultDoc.selectNodes("//userqueryid"); for (var i = 0; i < resultRecords.length; i++) { var text = resultRecords[i].selectSingleNode("//name").text; var value = i; crmForm.all.new_accsavedview.AddOption(text, value); } }
- Edited by Mohd Shams Monday, February 14, 2011 10:51 AM code formating
Monday, February 14, 2011 10:45 AM -
Pls some one help me.Tuesday, February 15, 2011 6:59 AM
-
Hi,
I retrieves all the user saved view with slightly changing the code.
Now I need, the selected item of picklist should be same as the values of "savedview" variable. When I add "crmForm.all.new_accsavedview.SelectedText = Savedview;" It add an extra value into picklist.
Code:
// Capture the result. var resultDoc = loadXmlDocument(XmlHttp.responseXML.text); // Process and display the results. (In order to retrieve the 'name' & userqueryid attributes) var resultRecords = resultDoc.selectNodes("//name"); var resultRecords1 = resultDoc.selectNodes("//userqueryid"); var Savedview = crmForm.all.new_name.DataValue; for (var i = 0; i < resultRecords.length; i++) { var text = resultRecords[i].text; var value = i; crmForm.all.new_accsavedview.AddOption(text, value); if(crmForm.FormType !=1) { if(Savedview == text) { crmForm.all.new_viewid.DataValue=resultRecords1[i].text; crmForm.all.new_accsavedview.SelectedText = Savedview; } } }
Tuesday, February 15, 2011 11:01 AM -
First remove all options from picklist
either by code
or manually.
Regards Faisal
Tuesday, February 15, 2011 11:34 AM -
Hi Faisal,
I have rectified this. I have replaced the code "crmForm.all.new_accsavedview.SelectedText = savedview " with "crmForm.all.new_accsavedview.DataValue= i ".
Now It working working fine but when I close the window it ask me save the save.
Tuesday, February 15, 2011 12:19 PM -
That's probably because you're changing the DataValue. If you don't intend to save changes to the "new_accsavedview" field, then write a bit of OnSave event code to Disable the field--at least, I think that'll work (to be honest, I don't think I've ever tried that). When a field is disabled, any changes to the data are ignored by the CRM UI.
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.- Proposed as answer by Jim Glass Jr Tuesday, February 15, 2011 10:12 PM
- Marked as answer by Mohd Shams Friday, February 18, 2011 8:55 AM
Tuesday, February 15, 2011 7:58 PMModerator