Showing posts with label Subgrid. Show all posts
Showing posts with label Subgrid. Show all posts

Tuesday, 6 September 2016

Modify the Delete (Dustbin icon) Button in the CRM Subgrid

Overview

Sometimes we need to modify the Delete button in the CRM Subgrid, example:

1. For preventing users to perform the delete button (but you dont want to just disable it)

2. Call another function or call custom function that needs client site programming (We can do plugin onDelete or onAssociate, but in case you want to show it in the client site)

3. To do impersonation

The Code

function modifyRibbon() {
    modifySubgridDeleteButtonEventHandler("subgrid_name_in_the_form", deleteSubgridRecord, true);
    discountStructureControl();
}

function deleteSubgridRecord() {
    alert("test");
}

function modifySubgridDeleteButtonEventHandler(subgridName, functionToCall, passGridControl) {
    try {
        //to store the original function ones
        var originalFunctionDeleteRecordSubgrid = Mscrm.GridCommandActions.deleteRecords;
        debugger;
        //add new standard subgrid
        Mscrm.GridCommandActions.deleteRecords = function (selectedControl, selectedControlSelectedItemReferences, selectedEntityTypeCode) {
            //if (typeof (gridControl.get_id).toString().toLowerCase() == "undefined") {} //no need since I replaced by the previous line
            if (selectedControl.get_id() != subgridName) {
                originalFunctionDeleteRecordSubgrid(selectedControl, selectedControlSelectedItemReferences, selectedEntityTypeCode);
            }
            else {
                if (passGridControl) {
                    functionToCall(selectedControl);
                }
                else {
                    functionToCall();
                }
            }
        }
    }
    catch (e) {

    }
}

Result

*After clicking the ‘Delete’ button

image

Note: This method is overwriting the CRM functions and it works for CRM 2013, for CRM 2015/2016, this function [Mscrm.GridCommandActions.deleteRecords] might have been changed, so need to find out the current function name based on your CRM Version. And again, it means it is unsupported Smile

Thanks!

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!

Tuesday, 25 August 2015

Modify CRM Subgrid Ribbon for CRM 2015 (Update 1)

Introduction

Based on my previous post we were talking about how to customize the subgrid ribbon in CRM 2013, now how about CRM 2015, especially after the latest update 1? Okay, here we go.

Solution

What we need to do is just replacing:

Mscrm.GridRibbonActions.addExistingFromSubGridStandard to Mscrm.GridCommandActions.addExistingFromSubGridStandard

Just replace the code only.
That’s why I use the form scripting to prepare another release update.

The Code

So the sample code will be like this:

function modifyRibbon() {
    //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.GridCommandActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

    //add existing standard subgrid
    Mscrm.GridCommandActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAddExistingStandard(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

    //add associate subgrid (N:N)
    Mscrm.GridCommandActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAssociated(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

}

function callPopUp(gridcontrol) {
    if (Xrm.Page.ui.getFormType() == 2) //update {
        //call the pop up
        var dialogoptions = new Xrm.DialogOptions;
        dialogoptions.width = 1080;
        dialogoptions.height = 750;

//*You can call pop up or modal dialog or web resource or other script, running dialog, running workflow, or javascript to call custom action
Xrm.Internal.openDialog('http://mycrmserver?id=' + Xrm.Page.data.entity.getId(),
       dialogoptions, null, null, function (retval) { gridcontrol.Refresh() });
        gridcontrol.Refresh();
    }
}

And the result you can get exactly the same, please put the code in the form and call during onload.

*For CRM 2013 please use this:
http://missdynamicscrm.blogspot.sg/2015/08/tweak-modify-ribbon-in-crm-2013-subgrid.html


Hope this helps!

Thanks.

Tweak & Modify Ribbon in CRM 2013 Subgrid

Introduction

As we know that ribbon/command in CRM 2013/2015 subgrid can only have ‘+’ button inside and you cannot add ribbon to appear in this subgrid design. Well, this behaviour you cannot change, you cannot add new ribbon, but it does not mean you cannot customize it!

So, I have requirement when the user click +, instead of choosing the existing record using CRM standard lookup (for add existing) or open new window for creating new record, they want to open another custom window, such as CRM Dialog, run custom workflow, run custom script with custom action combination as well, open new web resource, or open new custom website.

So, we can have options such as: Force users to use Associated View (well, this option is not the best option becase why did you even need to put subgrid if you enforce users to use associated view? Hm..in this case you might miss the CRM 2011 version.


So, we need to find the alternative like customizing the ribbon. Well, you cannot modify the behaviour, but I believe you can still achieve it by customizing the ribbon or even its action.

The title must be like Modifying Ribbon in CRM 2013 Subgrid without even modifying the ribbon XML (ribbondiff xml) customization.

Solution

As I read some good articles that it is not recommended to modify the out of the box standard ribbon/command bar, so I take it highly, so I decide to not modify the standard ribbon first, but I still need to fulfill the requirement.

Then, what I do is I try to override the standard function.

Yes, you can attach some script to override the Ribbon Action.

And the good thing here is you can apply the custom action without modifying the Ribbon.XML.
This will be useful to modify the Add New record in Subgrid, Add Existing records in Subgrid, and Add Associated records in Subgrid (N:N) relationship.

*To learn about the behaviour of the subgrid you can refer to these posts:


Then, what solution I did is just to put the additional logic to tweak the existing ribbon javascript calling.

So let’s get started

The Code

Here is the code, it is actually pretty simple if you know the CRM Scripting & basic Javascript overriding concept.

function modifyRibbon() {
    //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.get_id() != "subgrid_id") {
            originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

    //add existing standard subgrid
    Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAddExistingStandard(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

    //add associate subgrid (N:N)
    Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAssociated(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

}

function callPopUp(gridcontrol) {
    if (Xrm.Page.ui.getFormType() == 2) //update {
        //call the pop up
        var dialogoptions = new Xrm.DialogOptions;
        dialogoptions.width = 1080;
        dialogoptions.height = 750;
//You can call pop up or modal dialog or web resource or other script, running dialog, running workflow, or javascript to call custom action
Xrm.Internal.openDialog('http://mycrmserver?id=' + Xrm.Page.data.entity.getId(),
       dialogoptions, null, null, function (retval) { gridcontrol.Refresh() });
        gridcontrol.Refresh();
    }
}

Remember that this is the key:

//to store the original function ones
    var originalFunctionAddNewStandard = Mscrm.GridRibbonActions.addNewFromSubGridStandard;
    var originalFunctionAddExistingStandard = Mscrm.GridRibbonActions.addExistingFromSubGridStandard;
    var originalFunctionAssociated = Mscrm.GridRibbonActions.addExistingFromSubGridAssociated;

And this also mandatory to override:

//add new standard subgrid
    Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAddNewStandard(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

    //add existing standard subgrid
    Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAddExistingStandard(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

    //add associate subgrid (N:N)
    Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
        if (gridControl.get_id() != "subgrid_id") {
            originalFunctionAssociated(gridTypeCode, gridControl);
        }
        else {
            callPopUp(gridControl);
        }
    }

You can choose want to put in the N:N or 1:N subgrid only.

Which this one is optional and replaceable, replace it by your OWN CODE LOGIC

And this is the condition to whether you want to override the ribbon with your own custom action or not
if (gridControl.get_id() != "subgrid_id") 

Because once you implement this method, by default all subgrid will be overriden unless you want to exclude it, I just want to  make sure only applicable for the “subgrid_id” so I put that condition, for other subgrid it will still using the original one.

*You just need to put it in the form scripting and call on form onload

image

Result


*Alert action (if put alert action in the action logic)

image

*Calling the pop up

image

image

Then when I click the X button will refresh the ribbon because of this code:
function (retval) { gridcontrol.Refresh() }

Please refer to this for specific article:

http://inogic.com/blog/2014/09/alternative-to-showmodaldialog/

In this case, take not of this: Use of Xrm.Internal is unsupported as per SDK
But, anyway, in my post, this is just an example, you can change the logic to anything you want.
Can call custom dialog or workflow.

Mscrm.FormAction.launchOnDemandWorkflowForm
http://ribbonworkbench.uservoice.com/knowledgebase/articles/132235-create-a-workflow-short-cut-ribbon-button-no-code

Can refer to this good article:
http://ribbonworkbench.uservoice.com/knowledgebase/articles/140652-create-a-run-dialog-short-cut-ribbon-button

Or can use to open the modal popup (like my example) or open the entity form:
http://msdn.microsoft.com/en-us/library/gg328483.aspx

Or you can use to show alert and confirm dialog:
http://blogs.msdn.com/b/shraddha_dhingra/archive/2013/12/22/alertdialog-and-confirmdialog-in-crm-2013.aspx

Or even you can block user to add new record or link records:







All can be done using form scripting without even touching the ribbon.xml

*Note: This action is not documented in the SDK, use this to help you fulfil the requirement, The advantage on this action is in the next release, it might break, but you just need to modify the form scripting.

Like I did in CRM 2013 and CRM 2015, the scripting is changed from

Mscrm.GridRibbonActions.addExistingFromSubGridStandard to Mscrm.GridCommandActions.addExistingFromSubGridStandard

*For CRM 2015 you can refer to this article:
CRM 2015 Update 1 Code

This will be useful for you in case you do not want to use the standard subgrid function and there is no way like CRM 2011 you can have ribbon/command bar appearing same exactly like you have in Associated View.

Hope this helps!

Thanks.

Monday, 10 November 2014

Field Mapping from Opportunity/Quote/Order/Invoice to Product Lines does not Work in CRM 2013

There are many case submitted in the forum telling that the mapping between the Header and Product Lines, for example: Quote to Quote Product or Order to Order Product does not work.

Even though you have set the mapping properly

image

And please don’t tell about custom field first, because for the standard fields, such as Ship Address field, the mapping is also not working.

After spending some hours to research and dig, apparently, I learned something, a behavior, if you use Editable subgrid, you will not be able to make the mapping working.

image

When you double click the record, you will never see the field mapping works right now.

Check these forum posts to know similar scenario..

So now, what I should do?

Basically, I have submitted this issue to Microsoft because those records are created as new record from the subgrid, even though it is not a standard subgrid appearing in the earlier version, CRM 2011, it is supposed to bring along the field from the parent record as well.

So check this link and I hope you would like to vote it as well Smile 
Resolution:

1. If you want to keep using this editable subgrid, then the best way is to wait Microsoft Team to fix this issue, it might be in next version or next rollup release. Basically, we are expecting this mapping behavior also works not only for old-style CRM 2011 subgrid, but it is also for CRM 2013 subgrid as well.

2. To make it works, you need to replace your editable subgrid to the standard subgrid, so the mapping will work well.

See this:
image

My objective here is to copy the Ship to Address field from Quote header to Quote Product.

So, I change the subgrid, I replace this to my own created subgrid..

image

Replace it will your own subgrid..

image

And here is after Ok, Save, and Publish.

image

And it will makes a new pop up dialog form to key in the Quote Product

image

And as you can see the mapping is working very well.

This is one of the best solution because by replacing this subgrid you are not only having this supposed Mapping behavior, but you can also customize the View, including criteria, sorting, and of course additional columns selection, which those are not possible in the editable subgrid, you cannot modify that view even though you just want to add one more column. But, the consequence, you will lose the editable subgrid capability that firs introduced in CRM 2013.

3. I tried using OOB Workflow, but no luck, so if you have enough programming skills and of course enough time, what you can do is using a plugin or custom workflow activity to retrieve the value from the parent and copy it in to the product line in detail.

4. You can also using form scripting execute during onLoad to have an auto pre-filled fields copy from the Parent record field values.

Kindly, I hope this post can help you, especially for those, who are still blur or confused and still wondering find why and what happened with my Mapping, “I know I created properly, but what happened”?

Thank you.

Sunday, 9 November 2014

Filter Lookup Field by Related Subgrid Records in CRM

Sometimes we have requirement to choose lookup field value from the records that are listed in the related subgrid and we need to validate it so that the users won’t choose wrongly.

Let’s start with the example first.

You have lookup field in the Lead entity and you have a subgrid to list all of related Contractors.
Now, you have requirement to let the users to choose Primary Contractors from that list and validate it same as CRM did for selecting Primary Contact in the Account entity.

image

image

And if Look Up More Records

image

Yes, you can build a custom view or custom filter in the Lookup field, but is that too overkill? And let’s say you don’t have enough time or scripting skills so, what should you do?

In this post I am explaining about how to Filter a lookup field to show only records listed in the Related subgrid records.

I will use customized Case as another scenario with same concept with my first example and also same concept with Primary Contact in the Account entity.

Scenario: When you will need this circumstance?

In a Case entity, I have customized to be a Job Sheet Case for Spare Part Service Industry purposes and I have a subgrid to list all of the Case’s related Product Parts that want to be repaired as reparation service..
Now user A will have task to list all of the Parts.

image

Case and Product Parts are having N:N Relationship.

And I have a lookup to choose what is the Main Part that having major issue.

My client wants another user or the user himself to choose the Main Part with most major issue to choose and the system has to validate only to show the part from the available list, not another part, this is for analysis and escalation to next level purposes.

image

So..What can I do?

I know I can have a customer filtered lookup using javascript, but in fact CRM has capability to achieve this requirement without any custom code.

Resolution

1. Go to the Form Editor

2. Double click the lookup field to go to Field Property

3. Edit this property

Tick the ‘Only show records where:’

image

And to be safe, don’t allow users to turn off filter

4. You can also modify this additional property to manage the View

image

It will show when you click the Lookup in inline lookup and as well in the lookup more records.

To know more about the inline lookup, you can refer to this post:

5. As usual, Ok, Save, and Publish it.

Result:

Inline Lookup

*Before:
image

*After:
image

Lookup More Records..

*Before
image

*After
image

http://missdynamicscrm.blogspot.com/2014/09/crm-2013-modify-columns-shown-in-inline-lookup.html

Term and Condition

This is only works if the current entity and the entity records you want to filter are having relationship, either 1:N or N:N relationship.

Additional Info

So, now you know that without any custom code you can filter lookup to show only records from related entity without any custom code.

In my previous post, I have explained about how to filter lookup field by linked entity (only for N:1 relationship or Parent entity, for example relationship between Case and Account) fields as criteria.

In this post, we know how to filter lookup field by linked entity that having 1:N from this current entity record, no need any custom code. Even, filter lookup by related child records is easier.

So, those are tips and tricks to filter a lookup, choose your way to experience happy CRM-ing.

I hope this post can help you!
Thank you.

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.