Showing posts with label Associated View. Show all posts
Showing posts with label Associated View. Show all posts

Friday, 13 May 2016

Filter N to N (Many to Many) Subgrid Lookup for Existing Records in CRM Without Modifying the Ribbon Action

Introduction and Post References

Basically, in this post, I just want to show how to filter the N to N lookup in the subgrid in CRM Form, without even modifying the Global Subgrid Ribbon in CRM.

image

In my previous post: http://missdynamicscrm.blogspot.sg/2015/07/filter-nn-subgrid-in-crm-2013-using.html, I have explained about a way how to filter the N to N Subgrid Lookup, but that is needed to modify the ribbon action globally and you might need to set another condition to actually skip is you need to filter only on specific entity, but your grid will be appearing in many entities, such as:

You want to filter the Contact lookup in, if you modify the subgrid ribbon, in every contact subgrid, the filter will be applied and you might need extra code of criteria to actually limit the  execution.
Good thing about that if your entity only used for single entity and you don’t need to specify is that only for subgrid or associated view, then modifying the ribbon is a better solution. however, if you want to filter only subgrid in specific entity or form, you can actually using another way.

Like you can refer to my posts:


So, in this post, basically I try to combine the ways to become one solution, to filter the N to N lookup that only applicable once the user load the form using single javascript.  This is unsupported customization, but, remember, modifying the N to N view also needs unsupported customization, so yeah, to reach the requirement we have to go further for unsupported customization eventhough strongly I also not recommend.

The Code

So, I just try to combine the code becoming:

*For CRM 2013

function modifyRibbon(subgridName) {
    try {
        //to store the original function ones
        var originalFunctionAddNewStandard = Mscrm.GridRibbonActions.addNewFromSubGridStandard;
        var originalFunctionAddExistingStandard = Mscrm.GridRibbonActions.addExistingFromSubGridStandard;
        var originalFunctionAssociated = Mscrm.GridRibbonActions.addExistingFromSubGridAssociated;
        //add new standard subgrid
        Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
                }
                else {
                    originalFunctionAddNewStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }

        //add existing standard subgrid
        Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
        //add associate subgrid (N:N)
        Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
    }
    catch (ex) {
        alert(ex);
    }
}

*For CRM 2015

function modifyRibbon(subgridName) {
    try {
        //to store the original function ones
         var originalFunctionAddNewStandard = Mscrm.GridCommandActions.addNewFromSubGridStandard;
         var originalFunctionAddExistingStandard = Mscrm.GridCommandActions.addExistingFromSubGridStandard;
         var originalFunctionAssociated = Mscrm.GridCommandActions.addExistingFromSubGridAssociated;
        //add new standard subgrid
        Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
                }
                else {
                    originalFunctionAddNewStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }

        //add existing standard subgrid
        Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAddExistingStandard(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
        //add associate subgrid (N:N)
        Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
            if (gridControl != null) {
                if (gridControl.get_id() != subgridName) {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                }
                else {
                    originalFunctionAssociated(gridTypeCode, gridControl);
                    filterTrainerProfile(gridTypeCode, gridControl);
                }
            }
        }
    }
    catch (ex) {
        alert(ex);
    }
}

* So the filterTrainerProfile(gridTypeCode, gridControl); is your custom function to filter the view, some as you filter and create new custom view that I also have example in my previous post:
http://missdynamicscrm.blogspot.sg/2015/07/filter-nn-subgrid-in-crm-2013-using.html.

Remember, to get the GUID of the list record to show, you can always using CRM Javascript or in CRM 2013 and above you can use smarter way that is to combine with Custom Action, since Custom Action can be called through Javascript.

http://missdynamicscrm.blogspot.sg/search?q=custom+action

Hope this helps! Jiayou!

Friday, 30 January 2015

How to See Campaign Responses from Related Contact/Account/Lead

Overview

CRM has Campaign Response with related Customer data (can be Lead as well), but once you try to see from Contact, you cannot insert Campaign Response in the related entity section or subgrid.
So what if I want to see the Campaign Responses, for example from a Contact?
This blog will explain how to see the Campaign Response from Customer
By Default Campaign Response has a lookup field to Customer that can be Contact/Account/Lead.

campaignresponse

Can be done through Subgrid?

So it will be easy if you want to have subgrid in the Contact?

The answer is ‘No’

You cannot insert subgrid Campaign Response in the Contact Form, because Campaign Response is entity that included as Activity.

campaignresponse3

And also the lookup field here is Activity Party type, you didn’t link the Campaign Response with Contact as Regarding field right? And CRM has limitation in the subgrid, you can only insert Activity Subgrid and will see the list of Activity that related to the Contact if only the Activity regarding field is the Contact itself.

In the Subgrid, we can only select Activity that linked by Regarding Field (there is no Campaign Response in the available list)

image

So how do I see the Campaign Responses from my Customer.. Is that impossible?
The answer is also ‘No’.

Associated View is my Savior here…

Basically CRM has Associated View to show all Activities, including regarding field or as activity party.

So, choose the Contact and click the Chevron and choose the Activities

campaignresponse10

And it will open Associated View, now choose the All Activities.

campaignresponse13

As you can see you will see all of the Activities and you can see also the Campaign Response (see the Activity Type = Campaign Response), you can also see that the Regarding field is filled by Parent Campaign, not the Contact, so that, again, you cannot use the OOB Subgrid here.

Now, you can either use this ‘All Activities’ view or you can create a new View from the Activity.

1. Go to Activity entity and Views –> Create New

campaignresponse9

2. Give the proper name

campaignresponse5

3. Edit the Filter Criteria

campaignresponse6

Make sure you filter only to show Activity Type = Campaign Response

And you can also Add and Edit Display Columns
.
Now see the result…

Back to the Activity Associated View and choose the view from the selector to the newly created view.

campaignresponse12

That’s all..Is that so simple to see the Campaign Response from a Contact/Account/Lead?

*This post was made in particular to help answering this community query..



Hope this helps!
Thanks.

Sunday, 12 October 2014

CRM 2013 Subgrid vs. (Expanded) Associated View Records

Have you ever experienced when you have subgrid in your CRM Form, but when you click the ‘expand’ button to expand the view then it will redirect you to Associated View, but you found the records appear in the list are different?

If yes, then you might need to read this post.

If not, then you could read this post as well just in case you encounter this issue in the future.

To more detailed info about the real situation in practice, you can check this forum post:


and


When you put the sub grid into the form and you put the Associated view in the Left Navigation area during customization in Form Editor, you can see the subgrid records and you can open to expand the view.

image

*I have 2 records

Then, you realize that your associated view does not have the same list


* I can only see 1 record, where is the other record?

Okay, let’s go to the Root of Cause.

1. When you place a subgrid in the parent entity form, you will choose the view, right? Is that the records from related record or not and also what view you use.

For example, you choose ‘Recent Opportunities’ and ‘Only Related Records’.

You want to display Opportunities from Account.


2. If you found the issue I mentioned in the very beginning, then you might check the relationships.

In fact, you have more than 1 relationship.


3. So, what’s about? I have 2 relationship, so what?

Okay, now imagine that in the Opportunity perspective, you will have 2 fields.

- Account from relationship number 1 (hereafter will called as Account A)
- Account from relationship number 2 (hereafter will called as Account B)

For the records that you created from subgrid or associated view (quick create form as well) anything you create and then you choose from Account ABC for example, it will auto populate Account A and Account B set to ABC, because the mapping will work for record created from parent entity (it is how CRM relationship mapping takes role as behavior) and CRM does not know which relationship will be auto-filled, relationship #1 or relationship #2, so that CRM auto-populate both of those Account fields.

However, it won’t work for those records which created from outside of the parent subgrid or associated view, and won’t work for update or for existing record, it will work only for new record created.

*So, for example you create a new Opportunity, then you set the lookup field on Account A to ABC and Account B to XYZ, yes, it is possible. (remember this statement)
4. From the last statement in number 3, I mentioned about the lookup fields that can be different even though comes from same entity, Account.

This is very clear that the related records in the view of Account ABC and Account XYZ perspectives will return different related opportunities records.

If you go to Account ABC based on the relationship number #1 vs. relationship number #2, you will get different opportunity records.

See this table as reference:

Opportunity Account A Account B
Opp1 ABC XYZ
Opp2 ABC XYZ
Opp3 ABC ABC
Opp4 XYZ XYZ
Opp5 XYZ ABC

So, now you are in Account ABC from the relationship #1, you will get 3 opportunity records, otherwise from relationship #2, you will get 2 opportunity records only.

5. Now what happened if you found the subgrid and (expanded) Associated View are showing different result.

Basically, in the subgrid, it will show all of the Recent Opportunity records related to Account ABC based on your selected view (you can choose the view based on which relationship)

Then, in your CRM you have 2 relationships Account – Opportunity and you put a subgrid plus 2 associated view:


I found that if you don’t have any Associated View listed in the navigation area, it will not allow you to click the ‘Expand’ button to go to expanded Associated View, this is the key of the investigation.
6. Okay, then when you click the ‘expand’ image button, it will open the Associated View and now you have 2 Associated Views, CRM will not ask you which one you want to go, relationship #1 or relationship #2? In fact, CRM will redirect you to one of the associated view by default.

7. So, for example you put the subgrid based on the relationship #1, it will return you 3 Opportunities,

image

but when you click the expanded view, it is possible will show you different result.
It is possible to show you only 2 records from relationship #2 (Opp3 and Opp5)

image

8. Okay, I am done with the explanation, let’s back to the root of cause and the solution.
The main reason behind this behavior is you have more than 1 Associated View and CRM can redirect you to different Associated View, not exactly redirect you to the View based on the subgrid you have.

CRM will redirect you to the Associated View by Order or in Sequence.

Solution:

1. If you think the relationship #2 is not important (since you put relationship #1 as the view in the subgrid), you can just remove the Associated View.

2. If you think solution number #1 is not appropriate, you can try another proper solution, you can just re-order the order of the associated view, for example you swap the position.



I found this similar question in some posts and I hope it can help you!

Thank you.

Sunday, 24 August 2014

Display the Missing Associated View in CRM 2013

Sometimes, you need to show the Associated View from the Relationship in CRM 2013, you know that adding new subgrid might be making your Form UI looks cluttered, then you should go to the Form Editor and add the Navigation.

But, some relationship are hidden and cannot be shown in CRM 2013.

So, how do we handle this?

For example, we cannot show the Associated View of related Lead from Account/Contact and we cannot show the related Lead owned by User in User form.

So, to handle this case, you should create a custom Navigation link + the custom Web Resource, you should refer first to this link, Thanks to Amreek Singh for the nice post:

http://mscrmshop.blogspot.com/2013/01/step-by-step-tutorial-to-add-missing.html

But, in CRM 2013, since the User Interface was changed and the parameters required were revamped as well, so the constructed URL will give error if you apply to CRM 2013.

So, still using the methods mentioned in that great post, in CRM 2013 you should add another parameter.
In the building URL, you should use this:

 //building a url 
var sUrl = "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&pagemode=iframe&security=852023&tabSet=" + relName&rof=false&inlineEdit=1; 

Add the &inlineEdit=1 to show the CRM 2013 Command Bar (not Nav Bar)

So, the complete Web Resource code:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <style type="text/css">html,body{font-family: Segoe UI, Tahoma, Arial;background-color: #d6e8ff;border: 0px; margin: 0px; padding: 0px;}</style>
    <script type="text/javascript" language="javascript">

            //debugger;

            //get the context
            var Xrm = window.parent.Xrm;

            //get the current object id
            var oId = Xrm.Page.data.entity.getId();

            //get the object type
            var oType = Xrm.Page.context.getQueryStringParameters().etc;

            //set Relationship Name
            var relName = "lead_owning_user";

            //building a url var sUrl = "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&pagemode=iframe&security=852023&tabSet=" + relName&rof=false&inlineEdit=1;
           
            //get relative path with orgname as required
            var relativeUrl = Xrm.Page.context.prependOrgName(sUrl);
            
            window.location = relativeUrl;
   
    </script>
</head>
<body>
</body>
</html>

And this is the appearance of that ‘custom Associated View’

SNAGHTMLfe94b00

SNAGHTMLfe9851b

and with InlineEdit = 1

SNAGHTMLfe66d0d

*Remember, the behavior will be shown as expected if you show the web resource in the Navigation link in the parent Entity Form.

To make your job easier, you might try to test the URL first, copy it into the browser and execute it, before you put into the code.

The URL will be having this format:

http://servername:port/organizationname/userdefined/areas.aspx?oId=DB4A2D57-FBBA-E311-9403-  001CC4EECDD6&oType=1&pagemode=iframe&security=852023&tabSet=lead_customer_accounts&rof=false

Hope this helps!

Thanks.