Dynamics CRM 4.0 On Load Event populate field

Posted on 2011-05-11
Last Modified: 2012-08-13
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.
Question by:sbdt8631
    LVL 8

    Accepted 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

    LVL 8

    Expert Comment

    LVL 8

    Expert Comment

    Please update us about how you went with this?

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    .NET Xpath read sequence 5 40
    D3, SVG, dragging a star. 2 81
    RSS Feed Parsing for Images 5 38
    CRM 2011 Decimal Out of Range 2 19
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now