locked
Jscript problem RRS feed

  • Question

  • I am working on a script that would have the ability from a Contact record to display a window of all the parent customer addresses, select an address and populate the contact record with those address details. I am new to this level of scripting and have pieced gotten only so far. I now have the script to a point where it will display the addresses and let me select one but I get an error "Can't execute code from a freed script".  I see there was a hotfix some time back but we are on the latest rollup.

    Crm 2011 - On Premise - Rollup 5

     

    Script - 

    function customerid_onchange()
    {
    	// Get value of the selected customer account
    	var lookupItem = Xrm.Page.getAttribute('parentcustomerid').getValue();
    	//alert(lookupItem);
    
    		if (lookupItem != null)
    		{	
    
    			// Lookup Customer info
    			var url = '/' + Xrm.Page.context.getOrgUniqueName() +
    						'/_controls/lookup/lookupsingle.aspx?class=BrowseCustomerAddress&objecttypes=1071&browse=1&bindingcolumns=line1%2cpostalcode&parentType='
    					   + lookupItem[0].type + '&parentId='
    					   + lookupItem[0].id +
    						'&ShowNewButton=1&ShowPropButton=1&DefaultType=1071';
    			//alert(url);
    			// shows a modal window to select the addresses
    			var AccountLookUp = window.showModalDialog(url, null, 'dialogWidth:600px;dialogHeight:400px;resizable:yes');
    			//alert(AccountLookUp);
    				// Validate address info in not null before continuing
    				if (AccountLookUp != null && AccountLookUp != "undefined")
    				{
    
    					/*Get the value for the Addressid from the array and set it to a variable */
    
    					var AccountID = AccountLookUp[0].id;
    					//alert(AccountID);
    
    					var Accountxml = ""+
    					"<?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\">"
    					+
    					//Xrm.Page.context.getAuthenticationHeader()
    					decodeURI(GenerateAuthenticationHeader())
    					+
    					" <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>address</q1:EntityName>"
    					+
    					" <q1:ColumnSet xsi:type=\"q1:AllColumns\" />"
    					+
    					" <q1:Distinct>false</q1:Distinct>"
    					+
    					" <q1:Criteria>"
    					+
    					" <q1:FilterOperator>And</q1:FilterOperator>"
    					+
    					" <q1:Conditions>"
    					+
    					" <q1:Condition>"
    					+
    					" <q1:AttributeName>parentid</q1:AttributeName>"
    					+
    					" <q1:Operator>Like</q1:Operator>"
    					+
    					" <q1:Values>"
    					+
    					" <q1:Value xsi:type=\"xsd:string\">"
    					+
    					AccountID
    					+
    					"</q1:Value>"
    					+
    					" </q1:Values>"
    					+
    					" </q1:Condition>"
    					+
    					" </q1:Conditions>"
    					+
    					" </q1:Criteria>"
    					+
    					" </query>"
    					+
    					" </RetrieveMultiple>"
    					+
    					" </soap:Body>"
    					+
    					"</soap:Envelope>"
    					+"";
    
    
    					/*
    					Create the ActiveX object. 
    					*/
    
    					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", Accountxml.length);
    
    					xmlHttpRequest.send(Accountxml);
    
    					/* Set the XML response to a variable */
    
    					var resultAccountXml = xmlHttpRequest.responseXML;
    					alert(resultAccountXML);
    
    
    					var entityNodes = resultAccountXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
    
    					/* Loop through the collection of returned entities.*/
    					 
    					for (var i = 0; i < entityNodes.length; i++)
    						{
    
    							/* Access the current array element   */
    
    							var entityNode = entityNodes[i];
    
    							/* Attributes are child nodes of the BusinessEntity node. Use selectSingleNode to return
    							 the first occurrence of a named node. The selectNodes method we used before returns all
    							 matching nodes, but as an attribute name only occurs once, selectSingleNode is easier to use.
    							 Use the same namespace alias (q1) you have specified in the query.   */
    
    							var namenode = entityNode.selectSingleNode("q1:name");
    							var line1node = entityNode.selectSingleNode("q1:line1");
    
    
    
    							/* Always check for null values. If an attribute is set to null, it is not contained in the
    							resulting XML. And accessing accountidNode.text when accountidNode is null leads to
    							 a runtime error. */
    
    							var nameval = (namenode == null) ? null : namenode.text;
    							var line1val = (line1node == null) ? null : line1node.text;
    
    							/* Set the items on the CRM Form to allow input (only use if they are set to Read Only or Disabled).  */
    
    							//Xrm.Page.getAttribute("telephone1").setSubmitMode("always");
    							//Xrm.Page.getAttribute("emailyaddy").setSubmitMode("always");
    
    							/* Set the values retrieved from the Account to the corresponding fields on your Contact form.  */
    
    							Xrm.Page.getAttribute("address1_name").setValue(nameval);
    							Xrm.Page.getAttribute("address1_line1").setValue(line1val);
    
    						}
    
    
    
    				}
    
    		} // end of if no customer seelcted
    // end of new billing selected function
    }
    
    
    
    


    I would appreciate any help on this. I have tried to do quite a few searches and am running into a wall. I expect my issue lies in my code somewhere.

     

    Thanks,

     

    Josh

     

    Friday, December 9, 2011 7:20 PM

Answers

  • Well I've got it fixed. I redid part of the script and it is working. For anyone else out there who is looking to do something similar it works like a champ now.

     

    function customerid_onchange(){
    	// Get value of the selected customer account
    	var lookupItem = Xrm.Page.getAttribute("parentcustomerid").getValue();
    
    		if (lookupItem != null)
    		{
    			//alert(lookupItem);
    
    			// Lookup Customer info
    			var url = '/' + Xrm.Page.context.getOrgUniqueName() +
    						'/_controls/lookup/lookupsingle.aspx?class=BrowseCustomerAddress&objecttypes=1071&browse=1&bindingcolumns=line1%2cpostalcode&parentType='
    					   + lookupItem[0].type + '&parentId='
    					   + lookupItem[0].id + '&ShowNewButton=1&ShowPropButton=1&DefaultType=1071';
    
    			// shows a modal window to select the addresses
    			var selectedAddress = window.showModalDialog(url, null, 'dialogWidth:600px;dialogHeight:400px;resizable:yes');
    
    				// Validate address info in not null before continuing
    				if (selectedAddress != null)
    				{
    				   //alert(selectedAddress);
    				   var addressFields = selectedAddress.items;
    					// we have the id of the address -now use the json to get the values in an array.
    				    sLookupValue = addressFields[0].id;
    					//alert(sLookupValue);
    
    					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\">" +
    					decodeURI(GenerateAuthenticationHeader()) +
    					" <soap:Body>" +
    					" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    					" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryByAttribute\">" +
    					" <q1:EntityName>customeraddress</q1:EntityName>" +
    					" <q1:ColumnSet xsi:type=\"q1:ColumnSet\" >" +
    					" <q1:Attributes>" +
    					" <q1:Attribute>city</q1:Attribute>" +
    					" <q1:Attribute>country</q1:Attribute>" +
    					" <q1:Attribute>fax</q1:Attribute>" +
    					" <q1:Attribute>line1</q1:Attribute>" +
    					" <q1:Attribute>line2</q1:Attribute>" +
    					" <q1:Attribute>line3</q1:Attribute>" +
    					" <q1:Attribute>name</q1:Attribute>" +
    					" <q1:Attribute>postalcode</q1:Attribute>" +
    					" <q1:Attribute>primarycontactname</q1:Attribute>" +
    					" <q1:Attribute>stateorprovince</q1:Attribute>" +
    					" <q1:Attribute>telephone1</q1:Attribute>" +
    					" </q1:Attributes>" +
    					" </q1:ColumnSet>" +
    					" <q1:Attributes>" +
    					" <q1:Attribute>customeraddressid</q1:Attribute>" +
    					" </q1:Attributes>" +
    					" <q1:Values>" +
    					" <q1:Value xsi:type=\"xsd:string\">" + sLookupValue + "</q1:Value>" +
    					" </q1:Values>" +
    					" </query>" +
    					" </RetrieveMultiple>" +
    					" </soap:Body>" +
    					" </soap:Envelope>" + "";
    					
    					xml = xml.replace(/&#58;/g, ":");
    					xml = xml.replace(/&#47;/g, "/");
    
    					//window.clipboardData.setData("text", xml);
    					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);
    					
    					var resultXML = xmlHttpRequest.responseXml;
    
    					//alert(xmlHttpRequest.responseText);
    					var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    					oXmlDoc.async = false;
    					
    					oXmlDoc.loadXML(resultXML.xml);
    					
    					var businessEntities = oXmlDoc.getElementsByTagName('BusinessEntity');
    					/*if (businessEntities[i].selectSingleNode('./q1:name') != null)
    					{
    					alert(businessEntities[0].selectSingleNode('./q1:name').nodeTypedValue);
    					}
    					alert(businessEntities[0].selectSingleNode('./q1:city').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:country').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:line1').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:postalcode').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:stateorprovince').nodeTypedValue);
    					}
    					}
    					}		*/
    					
    					for (i=0; i< 1; i++)
    					{
    
    						if (businessEntities[i].selectSingleNode('./q1:name') != null)
    						{
    
    							// Address Name Set
    							  Xrm.Page.getControl("address1_name").setDisabled(false);
    							  Xrm.Page.getAttribute("address1_name").setValue(businessEntities[i].selectSingleNode('./q1:name').text);
    							  Xrm.Page.getAttribute("address1_name").setSubmitMode("always");
    							  Xrm.Page.getControl("address1_name").setDisabled(true);
    
    		
    							if (businessEntities[i].selectSingleNode('./q1:city') != null) {
    									// Address City set
    									Xrm.Page.getControl("address1_city").setDisabled(false);
    									Xrm.Page.getAttribute("address1_city").setValue(businessEntities[i].selectSingleNode('./q1:city').text);
    									Xrm.Page.getAttribute("address1_city").setSubmitMode("always");
    									Xrm.Page.getControl("address1_city").setDisabled(true);
    									}
    						
    							if (businessEntities[i].selectSingleNode('./q1:country') != null){
    									// Country set
    									Xrm.Page.getControl("address1_country").setDisabled(false);
    									Xrm.Page.getAttribute("address1_country").setValue(businessEntities[i].selectSingleNode('./q1:country').text);
    									Xrm.Page.getAttribute("address1_country").setSubmitMode("always");
    									Xrm.Page.getControl("address1_country").setDisabled(true);
    							}															
    							
    							if (businessEntities[i].selectSingleNode('./q1:line1') != null){
    									// Address Line 1 set
    									Xrm.Page.getControl("address1_line1").setDisabled(false);
    									Xrm.Page.getAttribute("address1_line1").setValue(businessEntities[i].selectSingleNode('./q1:line1').text);
    									Xrm.Page.getAttribute("address1_line1").setSubmitMode("always");
    									Xrm.Page.getControl("address1_line1").setDisabled(true);
    							}
    							if (businessEntities[i].selectSingleNode('./q1:line2') != null){
    									// Address Line 2 set
    									Xrm.Page.getControl("address1_line2").setDisabled(false);
    									Xrm.Page.getAttribute("address1_line2").setValue(businessEntities[i].selectSingleNode('./q1:line2').text);
    									Xrm.Page.getAttribute("address1_line2").setSubmitMode("always");
    									Xrm.Page.getControl("address1_line2").setDisabled(true);
    									}
    
    							
    							if (businessEntities[i].selectSingleNode('./q1:line3') != null){
    									// Address Line 3 set
    									Xrm.Page.getControl("address1_line3").setDisabled(false);
    									Xrm.Page.getAttribute("address1_line3").setValue(businessEntities[i].selectSingleNode('./q1:line3').text);
    									Xrm.Page.getAttribute("address1_line3").setSubmitMode("always");
    									Xrm.Page.getControl("address1_line3").setDisabled(true);
    									}
    
    
    							if (businessEntities[i].selectSingleNode('./q1:postalcode') != null){
    									// Address ZipCode set
    									Xrm.Page.getControl("address1_postalcode").setDisabled(false);
    									Xrm.Page.getAttribute("address1_postalcode").setValue(businessEntities[i].selectSingleNode('./q1:postalcode').text);
    									Xrm.Page.getAttribute("address1_postalcode").setSubmitMode("always");
    									Xrm.Page.getControl("address1_postalcode").setDisabled(true);
    									}
    
    							if (businessEntities[i].selectSingleNode('./q1:stateorprovince')!= null){
    									//Address State set
    									Xrm.Page.getControl("address1_stateorprovince").setDisabled(false);
    									Xrm.Page.getAttribute("address1_stateorprovince").setValue(businessEntities[i].selectSingleNode('./q1:stateorprovince').text);
    									Xrm.Page.getAttribute("address1_stateorprovince").setSubmitMode("always");
    									Xrm.Page.getControl("address1_stateorprovince").setDisabled(true);
    									}
    							
    						}// end if entity not empty
    					}// end for i++
    
    				}// end if no address selected
    		} // end of if no customer seelcted
    // end of new address selected function
    }
    
    


     


    • Edited by JoshJWilliams Wednesday, December 14, 2011 9:49 PM
    • Marked as answer by JoshJWilliams Wednesday, December 14, 2011 9:50 PM
    Wednesday, December 14, 2011 9:48 PM

All replies

  • Hi Josh,

    Your error is on

    if (AccountLookUp != null && AccountLookUp != "undefined")
    

    Replaced by

    if (AccountLookUp != null && typeof(AccountLookUp) != "undefined")
    


    Try use the solution of this article :

    RetrieveMultiple Calls in Jscript in Microsoft Dynamics CRM 2011

    http://mileyja.blogspot.com/2011/03/crm-2011-retrievemultiple-calls-in.html

     

    Regards,


    Philippe

    Blog : dynamicscrmcustomization

    Please remember to click "Vote as Helpful" and “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Proposed as answer by Philippe LEAL Sunday, December 11, 2011 4:20 PM
    Sunday, December 11, 2011 4:20 PM
  • Thanks for the reply. This did move me past that error but I still do not have a working solution. My error now is "Unable to get value of the property'id':object is null or undefined. It does not seem like I am getting values into the AccountLookup variable from the address that I am selecting.

    Thanks,

     

    Josh 

    Monday, December 12, 2011 6:56 PM
  • you should look at the code in CRM 2011 on the order and quote screen which allows you to select addresses for that customers and copy it the order/quote.

    in a way similar to what you are doing you can fire up the popup get the user to select an address and then instead of firing off some javascript you can just get the address values.

     

    the logic is the same in CRM 4 as in CRM 2011, you just need to use the new javascript

    http://www.stunnware.com/crm2/topic.aspx?id=JS26

     


    Ben Hosking
    Check out my CRM Blog
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, December 13, 2011 1:09 AM
  • I've tried this as well but can't get it to work in 2011. It may be too much of a change between 4.0 and 2011, not sure. I think I've been looking at this problem for too long and it's beginning to wear on me. I would not think this lookup would be too difficult. I've taken code from a past implementation that did this exact thing and it too gives me problems, mainly an authentication error (401) in which I cannot login to.  I'm back to the code above trying again as it basically mirrors the order/quote button functionality. If anyone has any more ideas I am open to anything at this point. 

    Thanks again,

     

    Josh


    Tuesday, December 13, 2011 9:55 PM
  • Well I've got it fixed. I redid part of the script and it is working. For anyone else out there who is looking to do something similar it works like a champ now.

     

    function customerid_onchange(){
    	// Get value of the selected customer account
    	var lookupItem = Xrm.Page.getAttribute("parentcustomerid").getValue();
    
    		if (lookupItem != null)
    		{
    			//alert(lookupItem);
    
    			// Lookup Customer info
    			var url = '/' + Xrm.Page.context.getOrgUniqueName() +
    						'/_controls/lookup/lookupsingle.aspx?class=BrowseCustomerAddress&objecttypes=1071&browse=1&bindingcolumns=line1%2cpostalcode&parentType='
    					   + lookupItem[0].type + '&parentId='
    					   + lookupItem[0].id + '&ShowNewButton=1&ShowPropButton=1&DefaultType=1071';
    
    			// shows a modal window to select the addresses
    			var selectedAddress = window.showModalDialog(url, null, 'dialogWidth:600px;dialogHeight:400px;resizable:yes');
    
    				// Validate address info in not null before continuing
    				if (selectedAddress != null)
    				{
    				   //alert(selectedAddress);
    				   var addressFields = selectedAddress.items;
    					// we have the id of the address -now use the json to get the values in an array.
    				    sLookupValue = addressFields[0].id;
    					//alert(sLookupValue);
    
    					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\">" +
    					decodeURI(GenerateAuthenticationHeader()) +
    					" <soap:Body>" +
    					" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    					" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryByAttribute\">" +
    					" <q1:EntityName>customeraddress</q1:EntityName>" +
    					" <q1:ColumnSet xsi:type=\"q1:ColumnSet\" >" +
    					" <q1:Attributes>" +
    					" <q1:Attribute>city</q1:Attribute>" +
    					" <q1:Attribute>country</q1:Attribute>" +
    					" <q1:Attribute>fax</q1:Attribute>" +
    					" <q1:Attribute>line1</q1:Attribute>" +
    					" <q1:Attribute>line2</q1:Attribute>" +
    					" <q1:Attribute>line3</q1:Attribute>" +
    					" <q1:Attribute>name</q1:Attribute>" +
    					" <q1:Attribute>postalcode</q1:Attribute>" +
    					" <q1:Attribute>primarycontactname</q1:Attribute>" +
    					" <q1:Attribute>stateorprovince</q1:Attribute>" +
    					" <q1:Attribute>telephone1</q1:Attribute>" +
    					" </q1:Attributes>" +
    					" </q1:ColumnSet>" +
    					" <q1:Attributes>" +
    					" <q1:Attribute>customeraddressid</q1:Attribute>" +
    					" </q1:Attributes>" +
    					" <q1:Values>" +
    					" <q1:Value xsi:type=\"xsd:string\">" + sLookupValue + "</q1:Value>" +
    					" </q1:Values>" +
    					" </query>" +
    					" </RetrieveMultiple>" +
    					" </soap:Body>" +
    					" </soap:Envelope>" + "";
    					
    					xml = xml.replace(/&#58;/g, ":");
    					xml = xml.replace(/&#47;/g, "/");
    
    					//window.clipboardData.setData("text", xml);
    					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);
    					
    					var resultXML = xmlHttpRequest.responseXml;
    
    					//alert(xmlHttpRequest.responseText);
    					var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    					oXmlDoc.async = false;
    					
    					oXmlDoc.loadXML(resultXML.xml);
    					
    					var businessEntities = oXmlDoc.getElementsByTagName('BusinessEntity');
    					/*if (businessEntities[i].selectSingleNode('./q1:name') != null)
    					{
    					alert(businessEntities[0].selectSingleNode('./q1:name').nodeTypedValue);
    					}
    					alert(businessEntities[0].selectSingleNode('./q1:city').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:country').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:line1').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:postalcode').nodeTypedValue);
    					alert(businessEntities[0].selectSingleNode('./q1:stateorprovince').nodeTypedValue);
    					}
    					}
    					}		*/
    					
    					for (i=0; i< 1; i++)
    					{
    
    						if (businessEntities[i].selectSingleNode('./q1:name') != null)
    						{
    
    							// Address Name Set
    							  Xrm.Page.getControl("address1_name").setDisabled(false);
    							  Xrm.Page.getAttribute("address1_name").setValue(businessEntities[i].selectSingleNode('./q1:name').text);
    							  Xrm.Page.getAttribute("address1_name").setSubmitMode("always");
    							  Xrm.Page.getControl("address1_name").setDisabled(true);
    
    		
    							if (businessEntities[i].selectSingleNode('./q1:city') != null) {
    									// Address City set
    									Xrm.Page.getControl("address1_city").setDisabled(false);
    									Xrm.Page.getAttribute("address1_city").setValue(businessEntities[i].selectSingleNode('./q1:city').text);
    									Xrm.Page.getAttribute("address1_city").setSubmitMode("always");
    									Xrm.Page.getControl("address1_city").setDisabled(true);
    									}
    						
    							if (businessEntities[i].selectSingleNode('./q1:country') != null){
    									// Country set
    									Xrm.Page.getControl("address1_country").setDisabled(false);
    									Xrm.Page.getAttribute("address1_country").setValue(businessEntities[i].selectSingleNode('./q1:country').text);
    									Xrm.Page.getAttribute("address1_country").setSubmitMode("always");
    									Xrm.Page.getControl("address1_country").setDisabled(true);
    							}															
    							
    							if (businessEntities[i].selectSingleNode('./q1:line1') != null){
    									// Address Line 1 set
    									Xrm.Page.getControl("address1_line1").setDisabled(false);
    									Xrm.Page.getAttribute("address1_line1").setValue(businessEntities[i].selectSingleNode('./q1:line1').text);
    									Xrm.Page.getAttribute("address1_line1").setSubmitMode("always");
    									Xrm.Page.getControl("address1_line1").setDisabled(true);
    							}
    							if (businessEntities[i].selectSingleNode('./q1:line2') != null){
    									// Address Line 2 set
    									Xrm.Page.getControl("address1_line2").setDisabled(false);
    									Xrm.Page.getAttribute("address1_line2").setValue(businessEntities[i].selectSingleNode('./q1:line2').text);
    									Xrm.Page.getAttribute("address1_line2").setSubmitMode("always");
    									Xrm.Page.getControl("address1_line2").setDisabled(true);
    									}
    
    							
    							if (businessEntities[i].selectSingleNode('./q1:line3') != null){
    									// Address Line 3 set
    									Xrm.Page.getControl("address1_line3").setDisabled(false);
    									Xrm.Page.getAttribute("address1_line3").setValue(businessEntities[i].selectSingleNode('./q1:line3').text);
    									Xrm.Page.getAttribute("address1_line3").setSubmitMode("always");
    									Xrm.Page.getControl("address1_line3").setDisabled(true);
    									}
    
    
    							if (businessEntities[i].selectSingleNode('./q1:postalcode') != null){
    									// Address ZipCode set
    									Xrm.Page.getControl("address1_postalcode").setDisabled(false);
    									Xrm.Page.getAttribute("address1_postalcode").setValue(businessEntities[i].selectSingleNode('./q1:postalcode').text);
    									Xrm.Page.getAttribute("address1_postalcode").setSubmitMode("always");
    									Xrm.Page.getControl("address1_postalcode").setDisabled(true);
    									}
    
    							if (businessEntities[i].selectSingleNode('./q1:stateorprovince')!= null){
    									//Address State set
    									Xrm.Page.getControl("address1_stateorprovince").setDisabled(false);
    									Xrm.Page.getAttribute("address1_stateorprovince").setValue(businessEntities[i].selectSingleNode('./q1:stateorprovince').text);
    									Xrm.Page.getAttribute("address1_stateorprovince").setSubmitMode("always");
    									Xrm.Page.getControl("address1_stateorprovince").setDisabled(true);
    									}
    							
    						}// end if entity not empty
    					}// end for i++
    
    				}// end if no address selected
    		} // end of if no customer seelcted
    // end of new address selected function
    }
    
    


     


    • Edited by JoshJWilliams Wednesday, December 14, 2011 9:49 PM
    • Marked as answer by JoshJWilliams Wednesday, December 14, 2011 9:50 PM
    Wednesday, December 14, 2011 9:48 PM