Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

Dynamics CRM 4.0 On Load Event populate field

I added a custom attribute picklist to the Opportunity form called New_FunnelPosition.  I added an identical custom attribute picklist to the email activity form.  When adding a new email activity I would like the form to obtain the value of new_FunnelPosition from the Opportunity view and default the value of the email picklist to the Opportunity value while allowing the user to choose another value.  I assume this will require XML code in the on load event in the customization of the form.
I am an XML dummy and don't know how to get started.  I do know other programming and think I can edit an example to fit my needs if I can get an example that is similar to what I need.
  • 3
1 Solution
What you need is a FetchXML (In onload event of Email activity) from opportunity to Email activity of the value from New_FunnlePosition.

You could use one of the tools from stunnware to generate FetchXML (the whole xml part assigned to the variable "var query" in below code)  and put that in one of my sample functions. Please note this is just a sample model and you could work out how you can proceed with this
Hope this helps
function fetchNewFunnelfromOpp()
var query =  "<fetch mapping='logical' count='50' version='1.0'>"+
	"<entity name='contact'>" +
		"<attribute name='address2_city' />"+
		"<attribute name='address2_country' />"+
		"<attribute name='address2_line1' />"+
		"<attribute name='address2_line2' />"+
		"<attribute name='address2_line3' />"+
		"<attribute name='address2_name' />"+
		"<attribute name='address2_postalcode' />"+
		"<attribute name='address2_stateorprovince' />"+
			"<condition attribute='contactid' operator='eq' value=" + recipientid + " />"+

  var myresult = crmForm.executeFetch(query);

       // Check for errors.
        var errorCount = myresult.selectNodes('//error').length;
        if (errorCount != 0)
            var msg = myresult.selectSingleNode('//description').nodeTypedValue;
            event.returnValue = false;
             return false;

	   //you could check if there are more than one record and alert the user saying there are more than one record found
            //assign the value fetched from the fetchxml
            for (i=0;i < results.length;i++)

              var Funnelname = results[i].selectSingleNode('New_FunnelPosition').nodeTypedValue;   

              crmForm.all.new_funnelposition.DataValue = Funnelname;

Open in new window

Please update us about how you went with this?

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now