Hello Scott,
First of all thanks for understanding my requirement.
Secondly, i am very weak at programming most of the time have worked for out of the box customization and a little bit of JS here and there from examples.
So here is the thing, yes i have done this before but my requirement was different. I linked the service activity with task and i was trying to set the regarding of service activity equal to the task regarding which i was sucessful by using the following code which i got from the web.
// Only make changes to this function; you may add this function to Form Onload Event,
// Field OnChange events etc.
function GetDetails() {
var EntityName, EntityId, AccountNumber, AccountEmailAddress, LookupFieldObject;
var PrimaryContactLookupId, PrimaryContactLookupName, PrimaryContactLookupType;
var resultXml;
LookupFieldObject = Xrm.Page.data.entity.attributes.get('parentcustomerid');
// If lookup field has value then the code will only run
if (LookupFieldObject.getValue() != null) {
//Fetch and place Entity Id (GUID) and Name (String) form lookup field into local variables
EntityId = LookupFieldObject.getValue()[0].id;
EntityName = LookupFieldObject.getValue()[0].entityType;
// Paramter explaination for function call
// RetrieveEntityById('account', AccountId, 'accountnumber,emailaddress1');
// 1st paramter requires entity name (not display or schema name) just pass it in a string
// i.e. for Account entity use 'account' for opportunity entity use 'opportunity'
// 2nd paramter requires entity Id (GUID Type) field which we have retrieved and stored in
// AccountId local variable
// 3rd paramter requires attributes to be retrieved schema name, if thrid attributed is
// required to be retrieved then use like: i.e. 'accountnumber,emailaddress1,telephone2'
resultXml = RetrieveEntityById(EntityName, EntityId, 'accountnumber,emailaddress1,primarycontactid');
// In retrieved XML document check if it has accountnumber attribute
if (resultXml != null && resultXml.selectSingleNode('//q1:accountnumber') != null) {
// If XML document has account number attribute then assign to local variable AccountNumber
AccountNumber = resultXml.selectSingleNode('//q1:accountnumber').nodeTypedValue;
//Display Account Number Value in a Message Box
alert("Account Number :" + AccountNumber);
//If required then use the below code line to set value in field on form
//Xrm.Page.data.entity.attributes.get('new_myaccountnumber').setValue(AccountNumber);
}
// In retrieved XML document check if it has emailaddress1 attribute
if (resultXml != null && resultXml.selectSingleNode('//q1:emailaddress1') != null) {
// If XML document has account number attribute then assign to local variable AccountEmailAddress
AccountEmailAddress = resultXml.selectSingleNode('//q1:emailaddress1').nodeTypedValue;
alert("Email Address :" + AccountEmailAddress);
//If required then use the below code line to set value in field on form
//Xrm.Page.data.entity.attributes.get('new_myemailaddress').setValue(AccountEmailAddress);
}
// In retrieved XML document check if it has primarycontactid lookup attribute
if (resultXml != null && resultXml.selectSingleNode('//q1:primarycontactid') != null) {
// If XML document has primarycontactid lookup attribute then assign to local variable
PrimaryContactLookupId = resultXml.selectSingleNode('//q1:primarycontactid').nodeTypedValue;
// If XML document has primarycontactid lookup attribute then assign to local variable
PrimaryContactLookupName = resultXml.selectSingleNode('//q1:primarycontactid').getAttribute("name");
// If XML document has primarycontactid lookup attribute then assign to local variable
PrimaryContactLookupType = resultXml.selectSingleNode('//q1:primarycontactid').getAttribute("type") ;
alert("Primary Contact Lookup Id :" + PrimaryContactLookupId);
alert("Primary Contact Lookup Name :" + PrimaryContactLookupName);
alert("Primary Contact Lookup Type :" + PrimaryContactLookupType);
}
}
}
// Do not make any changes to this function
function RetrieveEntityById(prmEntityName, prmEntityId, prmEntityColumns) {
var resultXml, errorCount, msg, xmlHttpRequest, arrayEntityColumns, xmlEntityColumns;
arrayEntityColumns = prmEntityColumns.split(",");
for (var i = 0; i < arrayEntityColumns.length; i++) {
xmlEntityColumns += "<q1:Attribute>" + arrayEntityColumns[i] + "</q1:Attribute>";
}
var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();
//Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='schemas.xmlsoap.org/.../& +
" xmlns:xsi='www.w3.org/.../XMLSchema-instance& +
" xmlns:xsd='www.w3.org/.../XMLSchema& +
authenticationHeader +
"<soap:Body>" +
"<Retrieve xmlns='schemas.microsoft.com/.../WebServices& +
"<entityName>" + prmEntityName + "</entityName>" +
"<id>" + prmEntityId + "</id>" +
"<columnSet xmlns:q1='schemas.microsoft.com/.../Query& xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
xmlEntityColumns +
"</q1:Attributes>" +
"</columnSet>" +
"</Retrieve></soap:Body></soap:Envelope>";
//call function to create Soap Request to ms crm webservice
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
resultXml = xmlHttpRequest.responseXML;
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert("Error Message : " + msg);
}
else {
return resultXml;
}
}
Now with this code i was able to get the regarding field of the related task entity. But now my requirement is even more complex, as my management team entity (custom entity) is a sub-grid in my opportunity form instead of a look-up field. Secondly, the management team can i have multiple records, can be 3 or 4 or 5 records.
Now if you could tell me that is it still possible with javascript or many of the experts have told me that you require plug-ins for the following requirement. In either case, can you suggest some examples as i have no idea for javascript or plug-ins.
I would highly appreciate your help in this case.
Thanking you in Anticipation.
Ahmed Zaveri