Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Pre-Populate Lookup Field If the user does not have access to data through impersonation

Posted on by 40

We have a requirement where the user will not have access to some of the data in 'ABC' entity. Based on certain conditions, the data should be fetched from this entity using impersonation and populate in the lookup field of a different form. Since the user has append to organization privilege he should be able to select the data.

ABC Entity Privilege – User can see the records where he is the owner.

ABC Data-

Id

ACC Name

Single Holder

Owner

123

453

ABC

James

456

453

CDE

James

123

453

ABC

Brian

456

453

CDE

Brian

 

CDE Entity Form–

Logged in User - Brian

ABC Field should display all the records basis ACC No. So he should be able to see below records in Lookup Field.

Id

ACC Name

Single Holder

Owner

123

453

ABC

James

456

453

CDE

James

123

453

ABC

Brian

456

453

CDE

Brian

Now through impersonation I can fetch the data but how to populate the data in pre search event of lookup field.

*This post is locked for comments

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Pre-Populate Lookup Field If the user does not have access to data through impersonation

    Hi Aliasgar,

    Sorry to have misunderstood your thought,

    As per my re-understanding, would your real requirement be below?

    You current user has prvActOnBehalfOfAnotherUser privilege,

    but he had retrieved ABC entity records which couldn't be retrievable for his current security role by impersonated user, 

    then now you would like to give a similar rendered result drop-down as addPreSearch function to lookup field ?

    (because "pre populated field" could only make me think of you were working impersonation with Web API at front-end, while I don't know whether plug-in could do it)

    Please point out whether there is still any misunderstand.

    Regards,

    Clofly

  • Aliasgar Profile Picture
    Aliasgar 40 on at
    RE: Pre-Populate Lookup Field If the user does not have access to data through impersonation

    This will not work as the user doesn't have the privilege. He can see the records where he is the owner. In your fetchXML condition you are fetching basis the owner.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Pre-Populate Lookup Field If the user does not have access to data through impersonation

    Hi Aliasgar,

    As per my understanding, were you going to filter records that are owned by current user in lookup field ?

    For more detailed description: you just want Brian to select ABC data/records that are owned by him when he visiting CDE Entity Form ?

    If so, a full code would be below to achieve your requirement:

    function AddPreSearch(executionContext) {
      var formContext = executionContext.getFormContext();
      var ownerid = Xrm.Utility.getGlobalContext().userSettings.userId.replace("{""").replace("}""");
      formContext.getControl("parentaccountid").addPreSearch(function() {
        FilterLookup(owneridformContext);
      });
    }

    function FilterLookup(owneridformContext) {

      var fetchXML = "<filter type=\"and\">" +
        "<condition value=\"" + ownerid + "\" attribute=\"ownerid\" operator=\"eq\" />" +
        "</filter>";

      formContext.getControl("parentaccountid").addCustomFilter(fetchXML);
    }

    Just fire AddPreSearch function at form onLoad event, and replace parameter in getControl with your ABC field logical name.

    my example is filtering parent accounts for current user in Account form.

    x002.JPG

    x001.JPG

    Regards,

    Clofly

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans