Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / business rules for 2 e...
Sales forum
Answered

business rules for 2 entities

Posted on by 448

Hi all

This is my scenario:

In my opportunities (Summary), I have a custom field in lookup with a custom table/entity (table "Scope").... next picture.

pastedimage1669811173276v1.png

in the 2nd tab of opportunity ("Utenti Collegati"), it's related a custom table with a series of users with their scope .... the same user can have more than one scope.

pastedimage1669811213859v2.png

As in 2nd picture, I need that the list had only the user with the same scope inserted in the summary of the opportunity we are working on.

There is a way to create a business rule between 2 fields of 2 tables (or more fields/tables)? Or I'm forced to use custom filter as addPreSearch?

In both cases, can someone indicate me examples for dummies (I'm totally new of these themes)?

thanks in advance

  • DiePic Profile Picture
    DiePic 448 on at
    RE: business rules for 2 entities

    If can help someone, I've solved this problem as follow, putting together the various pieces suggested in the post :

    insert in OnLoad function

    pastedimage1673000720223v1.png

    this the function

    pastedimage1673000973719v2.png

    Thanks to all

  • DiePic Profile Picture
    DiePic 448 on at
    RE: business rules for 2 entities

    Hi Leah Ju 

    thanks for your patience, I dont explain me well .... my english is terrible

    ....

    in the picture the relations between tables and fields

    pastedimage1670414976911v3.png

    - 'Utente Ambito' (user with its scope) is selected from table scope&users but the relation with table opportunity is field IDopportunity, because there will be more then 1 row in table scope&users with the same IDopportunity.

    - in table opportunity I've the the field scopeID previous selected from table scope (in tab Summary).

    I need to have in a variable the scopeID of table scope&users o filter the list of 'Utente Ambito' of table scope&users (by the scopeID alredy selected in Summary)...

    ...

    I think the problem is that the field 'Utente Ambito' contain the related ID of the table scope&users with table opportunity , the filter is on field scopeID of the table scope&users

  • Verified answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: business rules for 2 entities

    HI DiePic,

    I have tried to reproduce your question but there are still some problems:

    (1) 'Utente Ambito' is a lookup field related to which table?

    You said: In table Users&Scopes there is a field related to table Scopes (this table contains users with their scope, that can be more than one, as in 2nd picture).

    pastedimage1670403038886v1.png

    'Utente Ambito' related to Scopes or Users&Scopes? Which table does the current form belong to?

    (2) Is there a relationship between the ''users&scopes'' table and the ''opportunity'' table?

    You are contradicting each other with these two statements:

    1st table (Opportunity) and 3rd table (Users&Scopes) are not related.

    'Utente Ambito' is a lookup field based on table 'Users&Scopes'. The rows inserted in this table are related to their Opportunity trought the 'OpportunityID' field.

    (3)Elenco Utenti per Ambiente nell'Opportunita is one sub-grid related to 'Users&Scopes' table on the opportunity form?

    pastedimage1670403532615v2.png

  • DiePic Profile Picture
    DiePic 448 on at
    RE: business rules for 2 entities

    Hi Leah Ju 

    Yes 'Utente Ambito' is a lookup field based on table 'Users&Scopes'. The rows inserted in this table are related to their Opportunity trought the 'OpportunityID' field.

    I can in this way assign a team of users to this opportunity

    I need to retrieve the data in tab Summary (1st picture) field in table Opportunity and use it to filter the lookup field of 2nd picture ('Utenti Ambito' in table Users&Scopes)


    pastedimage1670321318088v2.png

    thanks for your help

  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: business rules for 2 entities

    Hi DiePic,

    The 'Utente Ambito' is lookup field? it is from 'Users&Scopes' table?

    Is it in the opportunity form?

    pastedimage1670319601548v1.png

  • DiePic Profile Picture
    DiePic 448 on at
    RE: business rules for 2 entities

    Hi Leah Ju 

    many thanks for your reply. This is my case.

    I've 3 tables:
    1-Opportunity
    2-Scopes
    3-Users&Scopes

    In table Opportunity there is a field related  to table Scopes (my 1st picture).
    In table Users&Scopes there is a field related to table Scopes (this table contains users with their scope, that can be more than one, as in 2nd picture).
    1st table (Opportunity) and 3rd table (Users&Scopes) are not related.
    I need that the 2nd lookup (2nd picture - tab Utenti Collegati) give a list of data of table Users&Scopes, filtered for choice inserted in 1st lookup (that is in summary tab).... remember that the 2 tables (Opportunity and Users&Scopes) are not related.
    I'm sure that only with some code is fixable, but my knowledge is too low for this, and I don't know how to.

  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: business rules for 2 entities

    Hi DiePic,

    Based on your description, you need filter second lookup field based on the first lookup value, Right?

    If so, you can set 'Only show records where' Property of the second lookup field(Utente Ambito) to achieve your goal without any business rules and custom codes.

    --Go Settings > Customizations >Customize the System > Entities > Opportunity > Forms, Double-click the lookup field.

    https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/special-field-properties-legacy?view=op-9-1#lookup-field-properties 

    pastedimage1670226103254v1.png

    Example:

    https://www.arbelatech.com/insights-resources/blog/how-to-filter-lookups-without-custom-code-in-dynamics-365-customer-engagement.html 

    Other ways to filter lookups:

    https://www.praxiis.co.uk/post/filtering-dynamics365-lookups 

  • DiePic Profile Picture
    DiePic 448 on at
    RE: business rules for 2 entities

    Hi Guido Preite 

    thanks for your reply.

    Can you indicate me some examples for dummies (I'm totally new of these themes)?

    I've not idea where I must insert the script.

    (grazie)

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,061 Moderator on at
    RE: business rules for 2 entities

    you need to use addPreSearch, to be more exactly you will need to reset the filter on the onchange event for the "Ambito" lookup (because if the "Ambito" changes from ERP to CRM you want that the filter on the lookup "Utente Ambito" is update to show only records with CRM and not ERP.

    So first you need to read the ID of the "Ambito" lookup so you can build the fetchxml of the addPreSearch in a similar way like

    var ambitoId = "...";
    var filter = "<filter type='and'>" +
    "<condition attribute='custom_attribute_inside_cr07a_athambuteopportunity' operator='eq' value='" + ambitoId + "' />" +
    "</filter>";

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans