locked
plugin to set the values of dropdown in case form based on account lookup value RRS feed

  • Question

  • Hi

    I have a requirement to write a plugin where..

    a)i have taken 2 dropdowns in case and same dropdowns in account form also.

    b)look up on case form with "account" as target

    c)if v select account 1 in account lookup field.. then the values of the dropdown fields of that respect account (i.e account 1) should be set automatically in case form dropdowns also.

    That means.. the values of account 1 dropdowns should be set in case form too.. and in the same way if i select account 2,3 etc, their respective dropdown values should be set in case form dropdowns

    Monday, April 14, 2014 11:04 AM

Answers

  • Hi,

    If you want to do this plugin you need to write create/update plugin on case entity to reach lookup and query account based on the id to get selected field and set those in case.

    Also you can easily implement this with JS code as well, onchange of lookup field query account entity and set optionset in case.

    HTH


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Terra1 Tuesday, April 15, 2014 5:44 AM
    Monday, April 14, 2014 12:28 PM
    Moderator
  • Hi,

    You can simply use retrieve method like below

      if(entity.Contains("new_selectac")
      Guid AccountID=entity.GetAttributeValue<EntityReference>("new_selectac").Id;

    //query account

      Entity resultset=service.Retrieve("account",AccountID,new ColumnSet(new String[]{"new_dropdown1", "new_dropdown2", "new_dropdown3"}));


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Terra1 Tuesday, April 15, 2014 8:50 AM
    Tuesday, April 15, 2014 6:53 AM
    Moderator

All replies

  • Hi,

    If you want to do this plugin you need to write create/update plugin on case entity to reach lookup and query account based on the id to get selected field and set those in case.

    Also you can easily implement this with JS code as well, onchange of lookup field query account entity and set optionset in case.

    HTH


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Terra1 Tuesday, April 15, 2014 5:44 AM
    Monday, April 14, 2014 12:28 PM
    Moderator
  • Hi, 

    iam using the below code to query .. but i want to how to add the guid of account for this statement 

    querybyexpression.Values.AddRange("");
    
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                    {
                        Entity entity = (Entity)context.InputParameters["Target"];
    
                        EntityReference accountlookup = (EntityReference)entity.Attributes["new_selectac"];
                        {
    
                            QueryByAttribute querybyexpression = new QueryByAttribute("account");
    
                            querybyexpression.ColumnSet = new ColumnSet("new_dropdown1", "new_dropdown2", "new_dropdown3");
                            //  Attribute to query
                            querybyexpression.Attributes.AddRange("accountid");
                            //  Value of queried attribute to return
                            querybyexpression.Values.AddRange("-------------");
    
                            //  Query passed to the service proxy
                            EntityCollection retrieved = service.RetrieveMultiple(querybyexpression);

    Tuesday, April 15, 2014 6:40 AM
  • Hi,

    You can simply use retrieve method like below

      if(entity.Contains("new_selectac")
      Guid AccountID=entity.GetAttributeValue<EntityReference>("new_selectac").Id;

    //query account

      Entity resultset=service.Retrieve("account",AccountID,new ColumnSet(new String[]{"new_dropdown1", "new_dropdown2", "new_dropdown3"}));


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Terra1 Tuesday, April 15, 2014 8:50 AM
    Tuesday, April 15, 2014 6:53 AM
    Moderator
  • Hi Mahender,

    Here i want to know how to give relation between account and case form so that the values from account form can be displayed in case form respective to the account selected in the lookup value..

    Iam using this below code to fullfill the requirement as below...

    I have a requirement to write a plugin where..

    a)i have taken 2 dropdowns in case and same dropdowns in account form also.

    b)look up on case form with "account" as target

    c)if v select account 1 in account lookup field.. then the values of the dropdown fields of that respect account (i.e account 1) should be set automatically in case form dropdowns also.

    That means.. the values of account 1 dropdowns should be set in case form too.. and in the same way if i select account 2,3 etc, their respective dropdown values should be set in case form dropdowns

                if (context.InputParameters.Contains("Target") && context.InputParameters
    
    ["Target"] is Entity)
                {
                    Entity entity = (Entity)context.InputParameters["Target"];
                    if (entity.LogicalName == "incident")
                    {
                        if (entity.Attributes.Contains("new_selectac"))
                        {
                            Guid AccountID = entity.GetAttributeValue<EntityReference>("new_selectac").Id;
                            Entity resultset = service.Retrieve("account", AccountID, new 
    
    ColumnSet(new String[] { "new_dropdown1", "new_dropdown2", "new_dropdown3" }));
                            EntityReference accountlookup = 
    
    (EntityReference)entity.Attributes["new_selectac"];
                            {
                                QueryExpression querybyexpression = new QueryExpression("account");     
                               querybyexpression.ColumnSet = new ColumnSet("new_dropdown1","new_dropdown2", "new_dropdown3");                           
                            }
                        }
    

    Friday, April 18, 2014 10:16 AM