You are on page 1of 6

if(crmForm.

FormType==1){
/////////////////////////////////////
////////////////Date //////////////
///////////////////////////////////
var myDate=new Date();
myDate.setDate(myDate.getDate()-1);
crmForm.all.scheduledend.DataValue = myDate;
////////////////////////////////////////////////////
///////////initialization////////////////////////////
///////////////////////////////////////////////////
crmForm.all.to.setAttribute("lookuptypes", "1,2");
if (document.getElementById('OnDemandWorkflowForm') != null){
document.getElementById('OnDemandWorkflowForm').style.display="none";
document.getElementById('convertActivity').style.display="none";
document.getElementById('_MBdocumentallRelatedInformationPaneExpanddocumentall
RelatedInformationPaneLoadContextDatafollowup').style.display="none";
}
var FFT = 1; // 0 for account , 1 for contact
///////////////////////////////////////////////////////////////////
///////////////// F I X ///////////////////////////////////////////
//////////////////////////////////////////////////////////////////
if(crmForm.all.regardingobjectid.DataValue!=null)
{
var hellox = new Array();
hellox = null;
hellox = crmForm.all.regardingobjectid.DataValue;
if(hellox[0]!=null)
{
var theKeyx ="contactid";
var AccountIDx = hellox[0].id;
var theTypex = hellox[0].typename;
if(theTypex =="account")
{
theKeyx = "accountid";
FFT=0;
}
else {
var Accountxml = ""+
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:x
si=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2
001/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>"+theTypex+"</q1:EntityName>"
+
" <q1:ColumnSet xsi:type=\"q1:AllColumns\" />"
+
" <q1:Distinct>false</q1:Distinct>"
+
" <q1:Criteria>"
+
" <q1:FilterOperaregardingobjectidr>And</q1:FilterOperaregardingobjectidr>"
+
" <q1:Conditions>"
+
" <q1:Condition>"
+
" <q1:AttributeName>"+theKeyx+"</q1:AttributeName>"
+
" <q1:Operaregardingobjectidr>Like</q1:Operaregardingobjectidr>"
+
" <q1:Values>"
+
" <q1:Value xsi:type=\"xsd:string\">"
+
AccountIDx
+
"</q1:Value>"
+
" </q1:Values>"
+
" </q1:Condition>"
+
" </q1:Conditions>"
+
" </q1:Criteria>"
+
" </query>"
+
" </RetrieveMultiple>"
+
" </soap:Body>"
+
"</soap:Envelope>"
+"";

/*
Create the ActiveX object. Once again, this is standard proregardingobjectidcol.
Notice the
last two lines that pass our Query XML that we created above.
*/

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");


xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2
007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", Accountxml.length);
xmlHttpRequest.send(Accountxml);
/* Set the XML response regardingobjectid a variable that can be parsed later.
*/
var resultAccountXml = xmlHttpRequest.responseXML;

/*
Create a container for the "nodes" retrieved. Essentially, these are just the
fields that are returned in the XML result.
*/
var entityNodesx = resultAccountXml.selectNodes("//RetrieveMultipleResult/Busine
ssEntities/BusinessEntity");
/* Loop through the collection of returned entities.
Note that the query above limits the result regardingobjectid a single entity,
so you will only find one
node. regardingobjectid be more specific, it could be 0 nodes as well, if you d
on??t have access regardingobjectid accounts
or your system is empty. */
for (var i = 0; i < entityNodesx.length; i++)
{
var entityNodex = entityNodesx[i];
if(entityNodex.selectSingleNode('//q1:parentcusregardingobjectidmerid') != null
&& crmForm.FormType==1){
var lookupObject = new Object;
var lookupObjectArray = new Array();
lookupObject.id = entityNodex.selectSingleNode('//q1:parentcusregardingobject
idmerid').nodeTypedValue;
lookupObject.typename = "account";
lookupObject.name = entityNodex.selectSingleNode('//q1:parentcusregardingobje
ctidmerid').getAttribute("name");
lookupObjectArray[0] = lookupObject;
crmForm.all.regardingobjectid.DataValue = lookupObjectArray;
crmForm.all.regardingobjectid.ForceSubmit = true;
} else {crmForm.all.regardingobjectid.DataValue = null;
}
}
///////////////////////
}
}
}
//////////////////////////////////////////////////////////////////
///////////account for account////////////////////////////////
/////////////////////////////////////////////////////////////////
if(FFT == 0)
{
crmForm.all.to.Value = null;
}
if(crmForm.all.regardingobjectid.DataValue!=null){
var hello = new Array();
hello = null;
hello = crmForm.all.regardingobjectid.DataValue;
if(hello[0]!=null)
{
var theKey ="contactid";
var AccountID = hello[0].id;
var theType = hello[0].typename;
if(theType =="account"){theKey = "accountid";}
var Accountxml = ""+
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:x
si=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2
001/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>"+theType+"</q1:EntityName>"
+
" <q1:ColumnSet xsi:type=\"q1:AllColumns\" />"
+
" <q1:Distinct>false</q1:Distinct>"
+
" <q1:Criteria>"
+
" <q1:FilterOperaregardingobjectidr>And</q1:FilterOperaregardingobjectidr>"
+
" <q1:Conditions>"
+
" <q1:Condition>"
+
" <q1:AttributeName>"+theKey+"</q1:AttributeName>"
+
" <q1:Operaregardingobjectidr>Like</q1:Operaregardingobjectidr>"
+
" <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. Once again, this is standard proregardingobjectidcol.
Notice the
last two lines that pass our Query XML that we created above.
*/
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2
007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", Accountxml.length);
xmlHttpRequest.send(Accountxml);
/* Set the XML response regardingobjectid a variable that can be parsed later.
*/
var resultAccountXml = xmlHttpRequest.responseXML;

/*
Create a container for the "nodes" retrieved. Essentially, these are just the
fields that are returned in the XML result.
*/
var entityNodes = resultAccountXml.selectNodes("//RetrieveMultipleResult/Busines
sEntities/BusinessEntity");
/* Loop through the collection of returned entities.
Note that the query above limits the result regardingobjectid a single entity,
so you will only find one
node. regardingobjectid be more specific, it could be 0 nodes as well, if you d
on??t have access regardingobjectid accounts
or your system is empty. */
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 selectSing


leNode regardingobjectid return
the first occurrence of a named node. The selectNodes method we used be
fore returns all
matching nodes, but as an attribute name only occurs once, selectSingle
Node is easier regardingobjectid use.
Use the same namespace alias (q1) you have specified in the query. */
var telephonenode = entityNode.selectSingleNode("q1:telephone1");
var emailnode = entityNode.selectSingleNode("q1:emailaddress1");
var adr1node= entityNode.selectSingleNode("q1:address1_line1");
var adr2node= entityNode.selectSingleNode("q1:address1_line2");
var adr3node= entityNode.selectSingleNode("q1:address1_line3");
////////////////////////////////////////////////////////////////////////////////
//////
if(theType =="account"&&entityNode.selectSingleNode('//q1:primarycontactid') !=
null && crmForm.FormType==1 && FFT==0){
var lookupObject = new Object;
var lookupObjectArray = new Array();
lookupObject.id = entityNode.selectSingleNode('//q1:primarycontactid').nodeTy
pedValue;
lookupObject.typename = "contact";
lookupObject.name = entityNode.selectSingleNode('//q1:primarycontactid').getA
ttribute("name");
lookupObjectArray[0] = lookupObject;
crmForm.all.to.DataValue = lookupObjectArray;
crmForm.all.to.ForceSubmit = true;
} else {
if (FFT==0) crmForm.all.to.DataValue = null;
}
////////////////////////////////////////////////////////////////////////////////
///////
////////////////////////////////////////////////////////////////////////////////
///////
/* Always check for null values. If an attribute is set regardingobjecti
d null, it is not contained in the
resulting XML. And accessing accountidNode.text when accountidNode is nu
ll leads regardingobjectid
a runtime error. */
var telephonenum = (telephonenode == null) ? null : telephonenode.text;
var adr1= (adr1node== null) ? null : adr1node.text;
var adr2= (adr2node== null) ? null : adr2node.text;
var adr3= (adr3node== null) ? null : adr3node.text;
var emailaddy = (emailnode == null) ? null : emailnode.text;
/* Set the items on the CRM Form regardingobjectid allow input (only use
if they are set regardingobjectid Read Only or Disabled). */
//crmForm.all.telephone1.ForceSubmit = true;
//crmForm.all.emailyaddy.ForceSubmit = true;
/* Set the values retrieved from the Account regardingobjectid the corre
sponding fields on your Contact form. */
crmForm.all.rotta_phone.DataValue = telephonenum;
crmForm.all.rotta_addressline1.DataValue =adr1;
crmForm.all.rotta_addressline2.DataValue =adr2;
crmForm.all.rotta_addressline3.DataValue =adr3;
//crmForm.all.emailaddress1.DataValue = emailaddy;
}
}}
}

You might also like