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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard