web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Show only current user owned record in lookup in D365 portal

(0) ShareShare
ReportReport
Posted on by

Hi All,

I'm trying to implement this functionality in D365 portal where I have a lookup field on entity form which should show only current user's owned record in it. Could you please help me how this can be achieved. 

Thank you very much for your kind response in advance! :) 

-Leo

I have the same question (0)
  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at

    you need an entity permissions for your lookup entity and set the proper relationship to the contact on the permission: docs.microsoft.com/.../assign-entity-permissions

  • LeoFernandas Profile Picture
    on at

    Hi Oliver,

    Thank you very much for answering my question.

    The two entities are named Project and Azure Apps where I have lookup called Project on Azure Apps entity and would like this project lookup show only related records. Also, these two entities do have 1:N relationship with contact entity.

    When you say lookup entity, can you please let me know which one should by my lookup entity here?

    -Leo

  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at

    in your case Project is the lookup entity

    so you need the entity permission for Project, and within the permission you set the contact relationship

    You might also consider having another permission for the Azure Apps entity as well, I understand you don't want contacts to view other records from other contacts

  • LeoFernandas Profile Picture
    on at

    Thank much! Yes, I do want the portal user to see only the records created by him and do not want to other project record from Azure App entity.

    Sure, I would have the same entity permission configured for Azure App entity as well.

    Could you please let me know if I need to go back to that particular entity forms and enable entity permissions and attach this permission with it? Also, is it okay if i just link existing authenticated web role with these entity permissions?

    -Leo

  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at

    Hi Leo

    Yes, just link the existing authenticated web role to the new entity permissions, unless you are using custom web roles and assigning to your contacts

    Yes, you need to go back to your entity lists / forms and check the "Enable entity permissions" flag

  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi Leo,

    Actually it is possible to custom filter lookup field in portal, but it needs some code work.

    For example, I'm using "Mod Administrator" user login the portal with the same name, and I have a "filterAccount"  lookup field on case create form in portal, and I want to only show the accounts whose owner is the current user "Mod Administrator".

    Let's do this.

    1.Go to Dynamics 365 portals, create a new Web Template and add custom fetchxml with liquid to get the userid of current user in D365.

    As we know, if we login portal with D365 user by Azure AD, a new contact with the same name of user will be created in D365, and if we use {{user.id}} in portal to get the current userid, this id is only the contact id in D365, not real  userid, so we need to create a fetchxml to get the real user id first and the condition is systemuser's fullname euqals contact's fullname.

    pastedimage1585905053659v3.png

    {% fetchxml feed %}
    
      
        
        
        
        
          
        
      
    
    {% endfetchxml %}{
      "results": [
        {% for item in feed.results.entities %}
          {
             "userid" : "{{ item.systemuserid }}"
          }{% unless forloop.last %},{% endunless %}
        {% endfor -%}
      ]
    }

    We want this fetchxml return us a json object, so remember to set the "MIME Type" to "application/json"!

    pastedimage1585905148601v4.png

    2.Create a page Template and select the web template we created above.

    pastedimage1585905263895v5.png

    Remember to Uncheck "Use Website Header and Footer".

    3.Create a web page.

    pastedimage1585905401357v6.png

    pastedimage1585905418875v7.png

    Now we will be able to get the retrieve result in Json format through this URL: https://portalname.powerappsportals.com/GetRealUserID_WebPage

    4.Create another web template with custom fetchxml to retrieve the accounts whose owner is current user and create page template and web page at the same time as what we did above.

    pastedimage1585904017584v1.png

    {% fetchxml feed %}
    
      
        
        
        
        
          
        
      
    
    {% endfetchxml %}{
      "results": [
        {% for item in feed.results.entities %}
          {
             "id" : "{{ item.accountid }}",
              "name": "{{ item.name }}"
          }{% unless forloop.last %},{% endunless %}
        {% endfor -%}
      ]
    }

    5.Go to the entity form you want to archive this requirement in portal, and go to Entity Form Metadata tab, create a new record, choose the lookup field you want to filter.

    pastedimage1585906258571v12.png

    pastedimage1585906258578v13.png

    Select the control style to "Dropdown" will show the lookup records in dropdown style and could be more easier to custom with JS code.

    6.Still in entity form and go to Additional Settings->Custom JavaScript.

    pastedimage1585905630149v8.png

    Add the following function out of $(document).read().

    function filterAccount(){
        var realUserID;
            $("#new_filteraccount").empty();
            //retrieve real userid
            $.getJSON( "/GetRealUserID_WebPage", function( data ) {
                if(data.results.length>0){
                    data.results.forEach(element => {
                        realUserID=element.userid;
                    });
                } 
            }
            );
            //retrieve accounts
            $.getJSON( "/FilterCustomerInCaseCreating_Page?userid=" realUserID, function( data ) {
                if(data.results.length>0){
                    //create option for each returned entity
                    console.log(data.results);
                    data.results.forEach(element => {
                        let option = document.createElement("option");
                        option.value = element.id;
                        option.innerText = element.name;
    
                        $("#new_filteraccount").append(option);    
                        console.log(1);               
                    });
                } 
            }
            );
        }

    Here the "#new_filteraccount" is the lookup field on my portal form ,so you should replace the correct field name of yours.

    And add this function in $(document).read() to trigger it when loading the form.

    And here's the result.

    My user owns 10 accounts in D365.

    pastedimage1585906025377v9.png

    And I could also only see 10 accounts in portal.

    1447.PNG

    You could also refer to the following links.

    https://stoneridgesoftware.com/using-liquid-templates-and-fetchxml-to-retrieve-data-in-a-dynamics-365-online-portal/

    http://dyn365apps.com/2017/09/14/dynamics-365-portals-liquid-templates-part-3-retrieve-data-using-fetchxml/

    https://www.dancingwithcrm.com/custom-lookup-filtering-powerapps-portal/

    Best Regards,

    Leo

  • LeoFernandas Profile Picture
    on at

    Hi Oliver,

    I did them all but I'm still seeing all records from Project lookup filed on Azure app entity.

     1)  Created two entity permissions, one for Project entity and the other one for Azure app entity,

          associated Authenticated user web role to those entity permission.

      2) Open the contact and assigned that web role.

      3) Cleared cache and opened the lookup to check the output. But it lists out all records irrespective of

         current portal user (contact).

    -Leo

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi Leo,

    Did you try my code and methods?

    If my answer helped you, please mark my answer as verified so that we could help other users with similar issues.

    Regards,

    Leo

  • LeoFernandas Profile Picture
    on at

    Hi Leo,

    Thank you very much for this work around. I did try this work around with all the steps you have mentioned but I'm still able to find all the record from Project lookup.

    But I have a question to ask here, in the last script, there are two pages you have mentioned that is,

    1)  $.getJSON( "/getrealuserid_webpage", function( data ) - this one is created to get system user id, I have replaced it with partial URL I have given while creating web page.

    2)  $.getJSON( "/getrealuseridproject_webpage?userid="+realUserID, function( data ) - to get related project, I have replaced this also with the partial URL given while creating other  web page. 

    Finally, to paste this complete javascript, I have modified it with schema name of lookup fields as well and did paste it in entity form. 

    Could you please correct me if the steps i followed are correct to get this done, 

    $(document).read(){

    function filterAccount(){
    var realUserID;
    $("#mxr_mixedrealitysolutionusingid1").empty();
    //retrieve real userid
    $.getJSON( "/getrealuserid_webpage", function( data ) {
    if(data.results.length>0){
    data.results.forEach(element => {
    realUserID=element.userid;
    });
    }
    }
    );
    //retrieve accounts
    $.getJSON( "/getrealuseridproject_webpage?userid="+realUserID, function( data ) {
    if(data.results.length>0){
    //create option for each returned entity
    console.log(data.results);
    data.results.forEach(element => {
    let option = document.createElement("option");
    option.value = element.id;
    option.innerText = element.name;

    $("#mxr_mixedrealitysolutionusingid1").append(option);
    console.log(1);
    });
    }
    }
    );
    }
    };

    -Leo

  • LeoFernandas Profile Picture
    on at

    Hi All, 

    I have just changed related record filter on the lookup which has resulted me to see only current portal user owned record. However, this is happening after I created the record and try to update the lookup field value while it shows all records on creation of new record.   

    pastedimage1586261527423v1.png

    Could anyone please help me how this it can be shown on create as well. Note that I have created entity permission for both entities with Global scope.  

    -Leo

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans