Refresh Parent Form from child entity in CRM.

Check out this wonderful article by Andriy (the master in CRM) on it.

http://a33ik.blogspot.com/2009/05/page-refresh.html

And the same code translated for CRM 3.0.

function timerHandler()
{
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\">" +
"  <soap:Body>" +
"    <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" +
"      <q1:EntityName>salesorder</q1:EntityName>" +
"      <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
"        <q1:Attributes>" +
"          <q1:Attribute>modifiedon</q1:Attribute>" +
"        </q1:Attributes>" +
"      </q1:ColumnSet>" +
"      <q1:Distinct>false</q1:Distinct>" +
"      <q1:Criteria>" +
"        <q1:FilterOperator>And</q1:FilterOperator>" +
"        <q1:Conditions>" +
"          <q1:Condition>" +
"            <q1:AttributeName>salesorderid</q1:AttributeName>" +
"            <q1:Operator>Equal</q1:Operator>" +
"            <q1:Values>" +
"              <q1:Value xmlns:q2=\"http://microsoft.com/wsdl/types/\" xsi:type=\"q2:guid\">"+crmForm.ObjectId+"</q1:Value>" +
"            </q1:Values>" +
"          </q1:Condition>" +
"        </q1:Conditions>" +
"      </q1:Criteria>" +
"    </query>" +
"  </soap:Body>" +
"</soap:Envelope>" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple&quot;);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var source = resultXml.selectSingleNode("//modifiedon").nodeTypedValue;
alert(source);
var firstpart = source.split(‘T’)[0];
var secondpart = source.split(‘T’)[1].split(‘+’)[0];
var parts =  firstpart .split(‘-‘);
var parts2 = secondpart.split(‘:’)
var modifiedon = new Date();
modifiedon.setYear(parts[0]);
modifiedon.setMonth(parts[1] – 1);
modifiedon.setDate(parts[2]);
modifiedon.setHours(parts2[0]);
modifiedon.setMinutes(parts2[1]);
modifiedon.setSeconds(parts2[2]);
if (modifiedon > openDate)
location.reload();
}
var openDate = new Date();
if (crmForm.FormType == 2)
setInterval(timerHandler, 1000);

 

Bye…


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s