Thursday, August 5, 2010

CRM 4.0 : To Show the 1:N entity in to an IFRAME

Hi All,
Here is the code to show the other entity 1:N (CRM left nav) in to an IFRAME.


crmForm.all.IFRAME_ReasonsforRejection.src = GetFrameSource("new_new_tripmanagement_new_tripmanagementreje");


function GetFrameSource(tabSet)
{
if (crmForm.ObjectId != null)
{
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet;
}
else
{
return "about:blank";
}
}

//Note:

/// To identify the GetFrameSource('XXXXXXXXXXXXXX');

// XX = relationship name(open the entity and identify the relationship which you created)

To Show the N:N Relationship entity in to an IFRAME.


crmForm.all.IFRAME_NatureofBusiness.src = GetFrameSourceNN(new_new_natureofbusiness_account');

//IFRAME_NatureofBusiness = Name of the IFrame.

function GetFrameSourceNN(tabSet)
{
if (crmForm.ObjectId != null)
{
var oId = crmFormSubmit.crmFormSubmitId.value;
var oType =crmFormSubmit.crmFormSubmitObjectType.value;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" +
security + "&roleOrd=2" + "&tabSet=area" + tabSet
}
else
{
return "about:blank";
}
}

//Note:

/// To identify the GetFrameSourceNN('XXXXXXXXXXXXXX');

// XX = relationship name(open the entity and identify the relationship which you created).


Cheers....!

CRM 4.0 : Retrieve Values using FetchXML.

Hi All,
Last week i have implemented to retrieve the values from an entity using fetchxml. hope this will be useful for our other development.


function populateTopicSubTopic(premise)
{
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = ""+
"
authenticationHeader+ ""+
"
<fetch mapping='logical'>"+
"<entity name='new_subtopic'>"+
"<attribute name='new_name'/>"+
"<attribute name='new_subtopicid'/>"+
"<attribute name='new_subtopicsid'/>"+
"<attribute name='new_subtopicsidname'/>"+
"<filter type='and'>"+
"<condition attribute='new_premisetype' operator='eq' value='"+premise+"'/>"+
"</filter>"+
"</entity>"+
"</fetch>
"+
"
"+
"
"+
"
";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
// Process and display the results.
else
{

// Capture the result and UnEncode it.
var resultSet = new String();
resultSet = resultXml.text;
resultSet.replace('<','<'); resultSet.replace('>','>');

// Create an XML document that you can parse.
var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false;
// Load the XML document that has the UnEncoded results.
oXmlDoc.loadXML(resultSet);
// Display the results.
var results = oXmlDoc.getElementsByTagName('result');
if (results.length>0)
{
var tlookupItem=new Object();
tlookupItem.id=results.item(0).selectSingleNode("new_subtopicid").text;
tlookupItem.typename='new_subtopic';
tlookupItem.name=results.item(0).selectSingleNode("new_name").text;
crmForm.all.new_subtopicid.DataValue=new Array(tlookupItem);

var stlookupItem=new Object();
stlookupItem.id=results.item(0).selectSingleNode("new_subtopicsid").text;
stlookupItem.typename='new_topic';

var topicname='';
if (results.item(0).getElementsByTagName('new_subtopicsid').item(0).attributes[0].name=='name')
{
topicname=results.item(0).getElementsByTagName('new_subtopicsid').item(0).attributes[0].text;
}
else if(results.item(0).getElementsByTagName('new_subtopicsid').item(0).attributes[1].name=='name')
{
topicname=results.item(0).getElementsByTagName('new_subtopicsid').item(0).attributes[1].text;
}
//stlookupItem.name=results.item(0).getElementsByTagName('new_subtopicsid').item(0).attributes[0].text;
stlookupItem.name=topicname;

crmForm.all.new_topicid.DataValue=new Array(stlookupItem);

return true;
}
else return false;
}
return false;
}


Cheers..!