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 :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 42

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

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    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

  • Aliasgar Profile Picture
    42 on at

    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
    25,210 on at

    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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans