Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Javascript/FetchXML OnChange working for me but not other Admin

$
0
0

We are on CRM 4.0 and I've implemented some JavaScript with FetchXML in it which should perform the following actions.

On my custom entity, I have a "Site" lookup field with a custom text field below it.  When the Site is populated or changed, the javascript should kick off and grab the Parent Account lookup from the Site.  Then, get the text of a field at the Parent Account level. After it has the text, it should populate the custom text field as mentioned at the beginning.  This all works fine for me but does not work at all for another Admin user. I need this to be working for all users and I am stumped as to what the problem is.

Does anyone have any ideas as to what could be the problem?  

Also, here is the JavaScript.

if (crmForm.all.new_siteid !=null)
{

if(crmForm.all.new_siteid.DataValue != null)
{ 

   GetSiteParent(crmForm.all.new_siteid.DataValue[0].id);
}

}


function GetSiteParent(siteId)
{
 var textReturn = "";

   if (siteId !=null)
   {
     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\">" + 
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>new_site</q1:EntityName>" + "    <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + "     <q1:Attributes>" + "      <q1:Attribute>new_siteid</q1:Attribute>" + "      <q1:Attribute>new_parentid</q1:Attribute>" + "      <q1:Attribute>new_schoolyearopen</q1:Attribute>" + "     </q1:Attributes>" + "    </q1:ColumnSet>" + "    <q1:Distinct>false</q1:Distinct>" + "    <q1:Criteria>" + "     <q1:FilterOperator>And</q1:FilterOperator>" + "     <q1:Conditions>" + "      <q1:Condition>" + "       <q1:AttributeName>new_siteid</q1:AttributeName>" + "       <q1:Operator>Equal</q1:Operator>" + "       <q1:Values>" + "        <q1:Value xsi:type=\"xsd:string\">" + siteId + "</q1:Value>" + "       </q1:Values>" + "      </q1:Condition>" + "     </q1:Conditions>" + "    </q1:Criteria>" + "   </query>" + "  </RetrieveMultiple>" + " </soap:Body>" + "</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);

var resultXml = xmlHttpRequest.responseXML;

//alert(resultXml);


if(resultXml !=null)
{  
  var parentId = resultXml.selectSingleNode("//q1:new_parentid").nodeTypedValue;

  if(parentId !="")
  {
    GetAccountCostCenter(parentId);
  }
  else
	{
		crmForm.all.new_costcenter.DataValue = null;
	}
}
}
	else
	{
		crmForm.all.new_costcenter.DataValue = null;
	}
//return textReturn;
}


function GetAccountCostCenter(accountId)
{
 var textReturn = "";

   if (accountId !=null)
   {
     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\">" + 
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>account</q1:EntityName>" + "    <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + "     <q1:Attributes>" + "      <q1:Attribute>accountid</q1:Attribute>" + "      <q1:Attribute>new_costcenter</q1:Attribute>" +"     </q1:Attributes>" + "    </q1:ColumnSet>" + "    <q1:Distinct>false</q1:Distinct>" + "    <q1:Criteria>" + "     <q1:FilterOperator>And</q1:FilterOperator>" + "     <q1:Conditions>" + "      <q1:Condition>" + "       <q1:AttributeName>accountid</q1:AttributeName>" + "       <q1:Operator>Equal</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>" + "";

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(resultXml);

if(resultXml !=null)
{  
  textReturn= retriveText(resultXml.selectNodes("//BusinessEntity/q1:new_costcenter"));

  if(textReturn !="")
  {
    crmForm.all.new_costcenter.DataValue = textReturn;
  }
  else
	{
		crmForm.all.new_costcenter.DataValue = null;
	}


}

} 

return textReturn;
}


function retriveText(InputNode)
{
 var text = "";
if (InputNode !=null)
{
 if(InputNode[0]!=null)
 {
 text =InputNode[0].text;
   }
  } 

 return text;
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>