locked
How to hard code a field using data from another entity RRS feed

  • Question

  • Hi,

    I am using CRM 4.0 and was wondering if it is possible to populate information from one entity to another

    I have 2 different entities both of which need similar information.

    Entity 1 (occupant) - this has a reference number (kf_reference) which is populated automatically from another system when a case is created.

    I then have  entity 2 (sscase) which needs to have the same reference

    The question is, is there a way in which when a new sscase is created (this is already linked to the occupant screen and has a lookup field containing the name of the person from the occupant entity) to populate the reference field on the sscase entity with the same information from the occupant screen

    Thanks in advance

    Kully  

    Monday, June 8, 2015 2:40 PM

Answers

  • If you haven´t already you should download the SDK for CRM http://www.microsoft.com/en-us/download/details.aspx?id=38 , it has been a while since I coded for CRM 4.0 and sadly I do not remember off the top of my head.

    First you need to retrieve the ID of the Occupant referenced entity on the SSCase form, something like (replace the bracket with the correct name)

    var occupantId = crmForm.all.[NAMEOFOCCUPANTFIELD].DataValue.id;

    Then you need to query the CRM for the Occupant entity to retrieve the kf_reference field.

    Something like the following, you need to replace the Uppercase names with correct field and entity names, in the code below.

    //Prepare variables for a occupant to retrieve. var lookupItem = new Array; // Get the lookup for the Occupant lookup attribute on the account form. lookupItem = crmForm.all.NAMEOFOCCUPANTLOOKUPFIELD.DataValue; //Here you need the name of the Occupant lookup field on the SSCase form. var occupantId = lookupItem[0].id; var authenticationHeader = GenerateAuthenticationHeader(); //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>NAMEOFOCCUPANTENTITY</entityName>"+ //Here you need the name of the occupant entity "<id>"+occupantId+"</id>"+ "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute>NAMEOF_KFREFERENCEIN_OCCUPANTENTITY</q1:Attribute>"+ //Here you need the name of the kf_reference field from the Occupant entity "</q1:Attributes>"+ "</columnSet>"+ "</Retrieve>"+ "</soap:Body>"+ "</soap:Envelope>"; //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/Retrieve"); 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); } //Display the retrieved value. else {

    //Here you need to set the name of the kf_reference field from the SScase entity Before the equal sign,
    //Here you need the name of the kf_reference field from the Occupant entity After the equal sgin crmForm.all.NAMEOFKFREFERENCEFIELDIN_SSCASEENTITY.DataValue = resultXml.selectSingleNode("//q1:NAMEOF_KFREFERENCEIN_OCCUPANTENTITY").nodeTypedValue; }


    There is a good chance you need to fix something from the code, but I hope it gets you in the right direction.


    Halldór Jóhannsson


    Monday, June 8, 2015 3:52 PM

All replies

  • If there can be a slight delay (couple of seconds) on having the data in the field you could go with something simple like a workflow that automatically fills in that field for you.

    You could go with a javascript that fires when the Occupant field is changed on the SSCase form (this only works when the form is used.)

    You could also go with a plugin that fills in the field.


    Halldór Jóhannsson

    Monday, June 8, 2015 2:48 PM
  • Hi Halldór,

    Thank you for your response, i think the javascript option is what i was looking for however i haven't had much luck in getting this to work.

    i was looking to add some script to the onload() event of the sscase entity which automatically populates the information from the occupant entity,

    Any ideas on how i could go about doing this.

    Thank you

    Kully  

    Monday, June 8, 2015 3:18 PM
  • If you haven´t already you should download the SDK for CRM http://www.microsoft.com/en-us/download/details.aspx?id=38 , it has been a while since I coded for CRM 4.0 and sadly I do not remember off the top of my head.

    First you need to retrieve the ID of the Occupant referenced entity on the SSCase form, something like (replace the bracket with the correct name)

    var occupantId = crmForm.all.[NAMEOFOCCUPANTFIELD].DataValue.id;

    Then you need to query the CRM for the Occupant entity to retrieve the kf_reference field.

    Something like the following, you need to replace the Uppercase names with correct field and entity names, in the code below.

    //Prepare variables for a occupant to retrieve. var lookupItem = new Array; // Get the lookup for the Occupant lookup attribute on the account form. lookupItem = crmForm.all.NAMEOFOCCUPANTLOOKUPFIELD.DataValue; //Here you need the name of the Occupant lookup field on the SSCase form. var occupantId = lookupItem[0].id; var authenticationHeader = GenerateAuthenticationHeader(); //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>NAMEOFOCCUPANTENTITY</entityName>"+ //Here you need the name of the occupant entity "<id>"+occupantId+"</id>"+ "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute>NAMEOF_KFREFERENCEIN_OCCUPANTENTITY</q1:Attribute>"+ //Here you need the name of the kf_reference field from the Occupant entity "</q1:Attributes>"+ "</columnSet>"+ "</Retrieve>"+ "</soap:Body>"+ "</soap:Envelope>"; //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/Retrieve"); 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); } //Display the retrieved value. else {

    //Here you need to set the name of the kf_reference field from the SScase entity Before the equal sign,
    //Here you need the name of the kf_reference field from the Occupant entity After the equal sgin crmForm.all.NAMEOFKFREFERENCEFIELDIN_SSCASEENTITY.DataValue = resultXml.selectSingleNode("//q1:NAMEOF_KFREFERENCEIN_OCCUPANTENTITY").nodeTypedValue; }


    There is a good chance you need to fix something from the code, but I hope it gets you in the right direction.


    Halldór Jóhannsson


    Monday, June 8, 2015 3:52 PM
  • Hi Halldór,

    Thank you very much this has worked a treat, code worked as is and i didnt need to fix it apart form adding the field names as suggested.

    Thank you very much again

    Wednesday, June 10, 2015 9:05 AM
  • I am glad to hear it worked out 8)


    Halldór Jóhannsson

    Wednesday, June 10, 2015 9:32 AM