Showing posts with label CRM 2011 SFA Opportunity. Show all posts
Showing posts with label CRM 2011 SFA Opportunity. Show all posts

Wednesday, August 24, 2011

Dynamics CRM 2011 : Opportunity Plugin Update Message Trigger on Opportunity Record Creation


On creating opportunity record if plugin is registered for Update event then it will automatically trigger and the code written for the Update event will be executed, to prevent from this erroneously behavior you can add a condition to check if plugin parent Context execution message is null then execute the code.

 [Plugin: C# Code]


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Crm.Sdk;

namespace wod.Crm.PluginDebugger
{
    public class wodPlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = 
            (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // check if parenet context message is Create and current contetx message is Update then return 
            //and does not execute code.
            if (context.MessageName == "Update" && context.ParentContext != null && 
                context.ParentContext.MessageName == "Create")
            {
                return;
            }
            else
            {
                // Write your update Opportunity record code here
            }

        }
    }
}



Thursday, June 2, 2011

Microsoft Dynamics CRM 2011 : How to Set Default Price List on Opportunity Form?


The pricelist choosing dialog has a filter built into it to present only the pricelists that use the selected currency. Since the workflow configuration does not offer currency selection, so no pricelists pass through the filter.

Instructions:

1. First retrieve the default price list id, open default price list record and copy the URL address.

(If you are using CRM application mode then press F11 to make address bar visible)

In my case URL is: http://mycrm:5555/myorg/main.aspx?etc=1022&extraqs=%3f_gridType%3d1022%26etc%3d1022%26id%3d%257b7EC1E3A2-6B8C-E011-A88AE5EF0498D042%257d%26rskey%3d490666710&pagetype=entityrecord

2. Decode CRM URL address, open web address http://meyerweb.com/eric/tools/dencoder

3. Paste the URL address into the URL Decoder/Encoder text area

4. Click two times on Decode button to decode Url address completely. Decoded URL: http://mycrm:5555/myorg/main.aspx?etc=1022&extraqs=?_gridType=1022&etc=1022&id={7EC1E3A2-6B8C-E011-A88AE5EF0498D042}&rskey=490666710&pagetype=entityrecord

5. Copy Id= value in my case it is {7EC1E3A2-6B8C-E011-A88A-E5EF0498D042} and use in default price list JScript.

6. Use the following Jscript code into Opportunity entity form Onload event and make sure to change the Price List Name and Price List Id in function frmOnLoad.

JScript Code:

// Call this function on Opportunity Form onLoad
function frmOnLoad() {
    // If form Type = Create
    if (Xrm.Page.ui.getFormType() == 1) {
        // 1st Parameter is Price List Name, 2nd Parameter is Price List GUID
        SetDefaultPriceList("Test", "{36A2E249-278D-E011-A88A-E5EF0498D042}");
    }
}
function SetDefaultPriceList(prmPriceListName, prmPriceListId) {
    //Create an array to set as the DataValue for the lookup control.
    var lookupData = new Array();
    //Create an Object add to the array.
    var lookupItem = new Object();
    //Set the id, typename, and name properties to the object.
    lookupItem.id = prmPriceListId;
    lookupItem.typename = "pricelevel";
    lookupItem.name = prmPriceListName;
    // Add the object to the array.
    lookupData[0] = lookupItem;
    // Set the value of the lookup field to the value of the array.
    Xrm.Page.getAttribute("pricelevelid").setValue(lookupData);
}