Display Parent / Child 1:N Relationship in Sub Grid - dynamics-crm

I have created a new entity called "Contracts" which has a lookup field called "Parent Contract", which refers its parent.
When I view a contract, I want to be able to display all contracts which refer to that contract as it's parent (i.e. the children).
I have created a view called "Associated Contracts" and have filtered on Related Contracts (Parent Contract).
I've added a sub-grid to the form, and set the data source to:
Records: Only Related Records
Entity: Contracts (Parent Contract)
Default View: Associated Contracts
But I get no records back! I am new to CRM, what am I doing wrong?
Edit:
Associated Contracts - Filter Criteria
All contracts in are set to active.

If you remove the part of the filter that only shows active parents, the subgrid should work as expected. Additionally, the subgrid will show related records no matter if the parent is active or inactive, which is standard behavior.
You can either edit your current Associated Contracts filter, or simply use one of the default views (e.g. Active Associated Contracts), depending on the columns you want to show.

By Default status reason for contracts is "Draft" can you add the column to the advanced find to see if they are infact "Active" or remove the filter criteria and start backtracking? I think you are mixing up state code and status code attributes.

Related

CRM 2016 - How to create a parent-child relationship with multiple parent types?

I have an entity - EntityZ, which has a ParentId where ParentId could be EntityA.Id, EntityB.Id or EntityC.Id. Is it possible to create this in MS Dynamics CRM 2016? If yes, how? I've looked but couldn't find a similar question or any help on the web.
An entity can be the child party in only one full parental relationship. When you are looking for a way to cascade record ownership, deletion a.o. between mutiple parent - child entities you can create configurable cascading relationships.
As Arun Vinoth pointed out you can design your entity as an activity type. However, this may conflict with the semantics of activity records in CRM. Also, doing this would make it possible to associate the child entity to any entity that is enabled for activities.
There’s a trade off to achieve this. Custom entity as Custom Activity
Creating custom entity EntityZ as custom activity and EntityA, B, C can act as parent.
EntityA or B or C can be chosen as RegardingObjectId of EntityZ.
This has security limitation like EntityZ will be visible to everyone as this will be listed like other activities (Email, Phonecall, Task, etc)
I think it is worth nothing that Dynamics 365 does contain and out-of-box "polymorphic" customer field.
This field can link to either an Account or Contact:
And while it can be kludgy, another option would be to create 3 lookups and only populate one. Once one is populated you could hide the other two. Or, you could have a "Parent Type" option set to determine which lookup to show.
It would be a bit messy to show three lookups in a view, with only one populated, so you might also want a Parent Name text field in to which you could concatenate the type and name. You could use a workflow to populate it, and then use it in views and reports.

How to auto-populate the look-up depends on the look up selected in Dynamic CRM?

I try using the workflow but it need to save the transaction before it populate, I try mapping it but doesn't work.
So I have a 3 Entities Expense,Vendor,Transaction.
In Vendor Entity I have a field of Vendor Name and a lookup field for Expense Category(Expense Entity).
In Transaction Entity I have a lookup for Vendor name and Expense Category, so when I select a vendor name in the lookup it will populate the lookup of expense category.
I already used the filter, yes it show the expense category depends on the vendor name selected, but the problem in there is I need to click the lookup field of expense tracker to show the value. I want is it will auto fill the lookup field without clicking it. Thank you
One of the way to achieve this is by using client side APIs. You may code something like that:
Upon vendor change:
Place a REST or Web API call to extract expense category ID and name
Populate the expense category lookup with category ID and name using client side XRM API
Another and much easier way is to create relationship mapping for expense category over vendor-transaction relationship. Then if user will create a transaction record using related entities area from within the vendor entity, the vendor and expense category both will get copied over the new record.
For a relationship mapping example please have a look over these links:
Save Time Entering Data into CRM by Mapping Fields between Records
TUTORIAL: Relationship Mappings
You could either setup mappings for Vendor and Expense, and create Transaction records only starting from Vendor records, or create a synchronous workflow to be run after Expense is created to copy over the field (in this second scenario, it doesn't matter how Transaction records are created, they'll always be populated, as long as you pick a Vendor).
You could also make your Expense in Transaction a Calculated field and make it always be the same as Vendor's value but it might not work for you (you aren't able to pick the value manually if you want it to be something else)

Show Order ID in Dynamics CRM Order Look up instead of Order Name

In Dynamics CRM 2016 (on-prem), I've custom child entity Partiesthat have a look of type order. Currently it is working properly and it is showing order name but I want it to show Order ID.
I tried to resolve by creating my own view, adding order id field only and making it default view for the look up but it don't meet my requirements.
This is controlled by the lookup view for Orders. The first three fields in the lookup view are shown when selecting records from the lookup field.
You cannot change the position of (or remove) the Name field from the lookup view. That still leaves you with two additional fields to be shown, one of which could be the Order ID.
I know no supported ways around this (except creating a workflow to copy the Order ID to the Name field and adding a custom name field instead, if you really insist).
Changing what appears on the form after you make a selection in a lookup field is not possible, unfortunately. The primary attribute is always what gets displayed after a user specifies a lookup value (which, for the Order entity, is the Name attribute). As Henrik's answer mentions, people commonly get around this by copying the value they want to see into the primary attribute using a workflow or a plugin.

Filtering instances not related to the current contact

I have a custom entity Stuff and it contains a lookup to Contact. I created a 1:N relation with the latter as primary and the former as related entity.
On the Contact's form I added a subgrid and I only wish to list the instances of Stuff that have the lookup pointing to the currently viewed Contact. However, when I choose Only Related Records, the custom entity isn't in the list (despite it being related via the 1:N relation).
So, I'm using All Record Types, instead, but that shows all the instances of Stuff and not, as I wish, only those that are related to the currently viewed member.
So, what's the best course of action here? Should I do something with the relation? Or build a custom filter in JavaScript? How can I make the Stuff related to Contact if it's at all possible?
The image below shows the available conditions for the related entities. I notice that none of them relates to Contact, though. Do I need to activate it somehow or am I approaching it from a totally wrong angle?
So to give you more detail, you add the grid on the form:
(This is coming from the contact Form edit, after you press add subgrid)
you select there only related records, this are the stuff record i created:
As you can see only 3 of them has a lookup pointing to a valid contact, from there if you look at the grid, is showing only the related ones as you selected during the grid creation:
In any case i update the answer this is how the relationship is defined, and is a simple lookup created from the stuff entity:

How can I add property to custom workflow activity that allows selection of another entity from workflow?

I'm working a custom workflow activity and would like to allow the user to select one of the entities available from within the workflow. This would be like selecting the entity in an update status activity. The list would include the primary entity, all of its associated parent entities, and any entities created within the workflow (e.g. if I created a task with the create activity, that task would be in the list).
Is there some way to do this?
Thanks!
Workflow has major shortcomings when it comes to things like this. You can add metadata to dependencies ( [CrmInput] and [CrmReferenceTarget("account")] ), but you'll need a property per entity you intend to support. I don't know if you could include multiple CrmReferenceTarget tags per property.
So even if you go through setting up a workflow activity with every lookup (which will require a code change for every new entity), you still have to take the care to set the right lookup in your code - and choose from ALL (not filtered based on your entity). Which is clearly not what you want.

Resources