Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Answered

How to make presearch work when presearchcallback is async

(0) ShareShare
ReportReport
Posted on by 305

I have a dropdown in a model driven app, and I want to add custom filter  to it  in presearch based on business logic. 

 

In my javascript code, the presearch callback has async await because it's using 

Xrm.WebApi.retrieveRecord to retrieve a record. But the custom filter is doing nothing when await is used in callback, it's only working if a remove the await in the callback .and hardcode the values that were otherwise being retrieved using await Xrm.WebApi.retrieveRecord
 

 

 

addPresearchToPayer = async function(executionContext) {
 
 var formContext = executionContext.getFormContext(); 
 var control = formContext.getControl("jg_fkpayer"); 
 await control.addPreSearch(addPresearchToPayerCallback);
}
 

 

 

 

Callback 

 

 

addPresearchToPayerCallback = async function (executionContext) {
var filter = await .....;
var control = executionContext.getEventSource();
 
 control.addCustomFilter(filter);
}
 

 

 

Categories:
  • Rutu01 Profile Picture
    305 on at
    Re: How to make presearch work when presearchcallback is async

    Thank you , i will be needing this on every form, so it's very helpful to know that this is a good way of doing it. 

  • Verified answer
    a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: How to make presearch work when presearchcallback is async

    @Rutu01 that's exactly what I wanted to suggest - store the value that you receive in async way in some kind of variable and use it when prefiltering is running.

  • Rutu01 Profile Picture
    305 on at
    Re: How to make presearch work when presearchcallback is async

    I have a Payer field which I need to custom filter based on Owner of the Record ( So that only Banks belonging to the same parent business unit as the Owner Team Or Third Party Payers like Tax Professionals and Sister Companies can be the Payer). I think i have it working now, i removed the async await from the callback, and instead put all the async operations like retrieveRecord  in  the Owner On Change event and stored that in a global variable. Now the callback is not async and so the presearch is working as expected. I hope this is a good workaround. Thank you for your comment, I thought it must be something simple I'm missing but guess it's not. If you have any suggestions please let me know 

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: How to make presearch work when presearchcallback is async

    Hello,

    I understand what are you talking about, I experienced similar challenges and unfortunately usage of async/await doesn't address the issue.

    Can you please provide what you want to achieve so I can help with architecting the solution?

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
stampcoin Profile Picture

stampcoin 15

#2
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 9 Super User 2025 Season 1

Overall leaderboard

Featured topics