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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to make presearch ...
Power Apps
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);
}
 

 

 

I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    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?

  • Rutu01 Profile Picture
    305 on at

    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 

  • Verified answer
    a33ik Profile Picture
    3,306 Most Valuable Professional on at

    @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

    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. 

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 408

#2
timl Profile Picture

timl 340 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 319

Last 30 days Overall leaderboard