locked
Dynamics CRM 4.0 dynamically populate a picklist from Fetch XML RRS feed

  • Question

  • //Dynamically populate varchar new_itemnumber as a picklist function SetItems() { var invid = crmForm.all.new_invoiceid.DataValue; var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; 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 += " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">"; xml += " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">"; xml += " <q1:EntityName>invoicedetail</q1:EntityName>"; xml += " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">"; xml += " <q1:Attributes>"; xml += " <q1:Attribute>productid</q1:Attribute>"; xml += "</q1:Attributes>"; xml += "</q1:ColumnSet>"; xml += "<q1:Distinct>false</q1:Distinct>"; xml += "<q1:Criteria>"; xml += "<q1:FilterOperator>And</q1:FilterOperator>"; xml += "<q1:Conditions>"; xml += "<q1:Condition>"; xml += "<q1:AttributeName>invoiceid</q1:AttributeName>"; xml += "<q1:Operator>Equal</q1:Operator>"; xml += "<q1:Values>"; xml += "<q1:Value xsi:type=\"xsd:string\">" + invid + "</q1:Value>"; xml += "</q1:Values>"; xml += "</q1:Condition>"; xml += "</q1:Conditions>"; xml += "</q1:Criteria>"; xml += "</query>"; xml += "</RetrieveMultiple>"; xml += "</soap:Body>"; xml += "</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/RetrieveMultiple"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); //alert(xml); var resultXml = xmlHttpRequest.responseXML; //alert(resultXml.xml); var Request = resultXml.getElementsByTagName("BusinessEntity"); if (Request.length == 0) { //alert("Aucune ville n'existe pour ce code postal"); return null; } else { if (Request[0].getElementsByTagName("q1:productid")[0] != null) { function ProdToPickList() { ConvertProdTextToPickList("new_itemnumber"); } function ConvertProdTextToPickList(controlId) { var textControl = document.getElementById(controlId); var picklistControl = document.createElement("SELECT"); picklistControl.id = textControl.id; picklistControl.req = textControl.req; picklistControl.className = "ms-crm-selectBox"; AddPickListValues(picklistControl); picklistControl.value = textControl.DataValue; textControl.parentElement.appendChild(picklistControl); textControl.parentElement.removeChild(textControl); } function AddPickListValues(picklistControl) { var items = resultXml.selectNodes("//BusinessEntity/q1:productid"); if(items != null) { for( i = 0; i < items.length; i++) { var option = document.createElement("OPTION"); option.innerText = items[i].text; picklistControl.appendChild(option); } } ProdToPickList(); } } }

    http://social.msdn.microsoft.com/Forums/en-US/crmdevelopment/thread/4f50b8c7-e9a8-40a6-a26c-76b5dcb9ea14

    I modified the code in the above thread to dynamically populate a nvarchar textbox called new_itemnumber as a picklist by selecting the product id's from the InvoiceDetail view based on an existing Invoice Id.  It is not working and I am not getting an error.  Any thoughts?

    GM

    Thursday, March 14, 2013 7:15 PM

Answers

  • Best bet is to stick a call to "debugger;" at the beginning and watch the program behave.  Add watches on variables that act as logic switches, so you can diagnose whether things are behaving as expected.  It's probably the simplest way to make sure that you're assuming all the right things.

    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 vasubabuk Friday, March 15, 2013 1:23 PM
    • Marked as answer by sbdt Thursday, March 21, 2013 6:23 PM
    Thursday, March 14, 2013 9:27 PM
    Moderator