Answered by:
lookup field in Case form

Question
-
Hi
i have an entitiy on the Case form called Phone would like to make it like the Customer field on the case form , to auto populate the phone number from the contact form same as the customer name is auto populated on the case form.
thanks
Monday, October 29, 2012 7:15 PM
Answers
-
I am not sure if i got your question clearly...
If you have added a phone field on case form and want to populate it based on the customer field selection, you have two options to go with
1. Edit the account-incident relationship and add a new field mapping to copy account phone to case phone. Repeat the same process for contact entity.
2. The above will only populate if the new case is created from within the context of the account or contact form. If you want to bring over the phone when a customer is selected manually on case form, you will need to write a script to read phone from account/contact and set it on case form.
HTH
Sam
Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Tuesday, October 30, 2012 12:52 AM -
Thanks Sam,
what i want is to show the phone on the Contact entity not the account on the case form
to populate the contact phone when the case is created from the contact context.
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Monday, November 19, 2012 7:10 AM -
Hi,
If you are creating a case related to contact i.e from the contacts left navigation. Then the mapping should do it for you. Go to relationships and then create the mapping of the fields you require. You can map the phone field to you field in the case form. Hope this helps. Let me know if you have any questions.
Thanks,
Prasad.
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Monday, November 19, 2012 7:34 AM -
ok you can achieve this using JavaScript.
function GetDetails() { var EntityName, EntityId, LastName; var resultXml; LookupFieldObject = Xrm.Page.data.entity.attributes.get('LookUpfieldLogicalName_inCase'); if (LookupFieldObject.getValue() != null) { EntityId = LookupFieldObject.getValue()[0].id; EntityName = LookupFieldObject.getValue()[0].entityType; resultXml = RetrieveEntityById(EntityName, EntityId,'phoneFieldLogicalName_inContact'); if (resultXml != null && resultXml.selectSingleNode('//q1:phoneFieldLogicalName_inContact') != null) { phoneNumber= resultXml.selectSingleNode('//q1:phoneFieldLogicalName_inContact').nodeTypedValue; Xrm.Page.data.entity.attributes.get('phoneFieldLogicalName_inCase').setValue( phoneNumber); } } } // 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='http://schemas.xmlsoap.org/soap/envelope/'" + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" + authenticationHeader + "<soap:Body>" + "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + "<entityName>" + prmEntityName + "</entityName>" + "<id>" + prmEntityId + "</id>" + "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/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", "http://schemas.microsoft.com/crm/2007/WebServices/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; } }
use GetDetails() function onChange of Lookup Field in Case.
Above code uses SOAP. you have to add JQuery.Js and json2.js files to your form before using the above code. look at this link to know how to add those files.
Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Proposed as answer by Ravitheja J Monday, November 19, 2012 7:40 AM
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Monday, November 19, 2012 7:39 AM
All replies
-
I am not sure if i got your question clearly...
If you have added a phone field on case form and want to populate it based on the customer field selection, you have two options to go with
1. Edit the account-incident relationship and add a new field mapping to copy account phone to case phone. Repeat the same process for contact entity.
2. The above will only populate if the new case is created from within the context of the account or contact form. If you want to bring over the phone when a customer is selected manually on case form, you will need to write a script to read phone from account/contact and set it on case form.
HTH
Sam
Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Tuesday, October 30, 2012 12:52 AM -
Thanks Sam,
what i want is to show the phone on the Contact entity not the account on the case form
to populate the contact phone when the case is created from the contact context.
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Monday, November 19, 2012 7:10 AM -
hello 2Day,
u wanted to populate phone number(from contact) when a case is created from the contact right ?
Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Monday, November 19, 2012 7:17 AM -
Yes CRMIG,Monday, November 19, 2012 7:25 AM
-
Hi,
If you are creating a case related to contact i.e from the contacts left navigation. Then the mapping should do it for you. Go to relationships and then create the mapping of the fields you require. You can map the phone field to you field in the case form. Hope this helps. Let me know if you have any questions.
Thanks,
Prasad.
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Monday, November 19, 2012 7:34 AM -
ok you can achieve this using JavaScript.
function GetDetails() { var EntityName, EntityId, LastName; var resultXml; LookupFieldObject = Xrm.Page.data.entity.attributes.get('LookUpfieldLogicalName_inCase'); if (LookupFieldObject.getValue() != null) { EntityId = LookupFieldObject.getValue()[0].id; EntityName = LookupFieldObject.getValue()[0].entityType; resultXml = RetrieveEntityById(EntityName, EntityId,'phoneFieldLogicalName_inContact'); if (resultXml != null && resultXml.selectSingleNode('//q1:phoneFieldLogicalName_inContact') != null) { phoneNumber= resultXml.selectSingleNode('//q1:phoneFieldLogicalName_inContact').nodeTypedValue; Xrm.Page.data.entity.attributes.get('phoneFieldLogicalName_inCase').setValue( phoneNumber); } } } // 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='http://schemas.xmlsoap.org/soap/envelope/'" + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" + authenticationHeader + "<soap:Body>" + "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + "<entityName>" + prmEntityName + "</entityName>" + "<id>" + prmEntityId + "</id>" + "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/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", "http://schemas.microsoft.com/crm/2007/WebServices/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; } }
use GetDetails() function onChange of Lookup Field in Case.
Above code uses SOAP. you have to add JQuery.Js and json2.js files to your form before using the above code. look at this link to know how to add those files.
Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Proposed as answer by Ravitheja J Monday, November 19, 2012 7:40 AM
- Marked as answer by 2Day Monday, November 19, 2012 8:13 AM
Monday, November 19, 2012 7:39 AM -
Thanks Guys
i did it by doing relationship and mapping
Monday, November 19, 2012 8:13 AM