Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

Filtering the record owners in the header of a form

(0) ShareShare
ReportReport
Posted on by 223

Hi All

 

We currently have a request to filter the owner search pane within a form to only display user accounts, not accounts that are created by the system (including the '#').

NativeNass__0-1695973453659.png

 

When we try to change the owner, we see all of these system generated accounts.

NativeNass__1-1695973569560.png

 

sidenote: editing the lookup view of the user table is not an option because then this would be applicable to all applications within this environment, it only needs to be on this specific form so as far as we know, JavaScript is the only way.

 

The JS we implemented on the onLoad event of the complete form is the following;

 

function onChangeOwner() {
var Sdk = window.Sdk || {};


Sdk.setOwnerIdFilter = function (executionContext) {

 // get the form context
 formContext = executionContext.getFormContext();
 formContext.getControl("header_ownerid").addPreSearch(Sdk.filterOwnerId);
}

Sdk.filterOwnerId = function () {

 var ownerIdFilter = "<filter type='and'><condition attribute='fullname' operator='not-begin-with' value='#' /></filter>";
 formContext.getControl("header_ownerid").addCustomFilter(ownerIdFilter, "systemuser");
}
}

 

but we can't get it to work, it keeps showing all of the users when searching.

 

Thanks for the help and sorry if I define myself to be a little unclear, still figuring out the customizations of Model Driven Apps.

  • NativeNass_ Profile Picture
    223 on at
    Re: Filtering the record owners in the header of a form

    @a33ik 

     

    Thanks a lot!

    This works!

     

    Thank you for your help & kind regards

  • Verified answer
    a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Filtering the record owners in the header of a form

    Hello,

    Try the following code out:

    function onLoad(executionContext) {
     var formContext = executionContext.getFormContext();
     formContext.getControl("header_ownerid").addPreSearch(filterOwnerId);
    }
    
    function filterOwnerId(executionContext) {
     var formContext = executionContext.getFormContext();
     var ownerIdFilter = "<filter type='and'><condition attribute='fullname' operator='not-begin-with' value='#' /></filter>";
     formContext.getControl("header_ownerid").addCustomFilter(ownerIdFilter, "systemuser");
    }

     

    Add onLoad to handle the Load event of the form and don't forget to check "Pass Execution Context as First Parameter" checkbox.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

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 - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 75 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 51 Super User 2025 Season 1

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 36

Overall leaderboard