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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Presearch filter based on Option Set attribute value using js

(0) ShareShare
ReportReport
Posted on by 595

Hi All, 

I have an requirement that I need to add Presearch filter based on option set value using js.

Please help me to achieve this

Code :

var Sdk = window.Sdk || {};
Sdk.setRoleUserFilter = function (executionContext) {
formContext = executionContext.getFormContext();
//var CurrentUserId = Xrm.Utility.getGlobalContext().userSettings.userId;
formContext.getControl("sysdef_user").addPreSearch(Sdk.filteruser);
}
Sdk.filteruser = function () {

var TeamID = formContext.getAttribute("sysdef_team").getValue()[0].id;
let options = "?$select=sysdef_role";
Xrm.WebApi.retrieveRecord("sysdef_teammaster", TeamID, options).then(function success(result) {
if (isNotNull(result.sysdef_role)) {
console.log("sysdef_role: "+result.sysdef_role);
var roleval=result.sysdef_role;
var customerAccountFilter = "<filter type='and'><condition attribute='firstname' operator='eq' value='767580000'/></filter>";
formContext.getControl("sysdef_user").addCustomFilter(customerAccountFilter,"systemuser");//adding filter for user lookup from systemuser entity
}
},
function (error) {
console.log(error);
});


}

I'm trying with above code but I'm not getting expected result. Where I'm wrong?

Any Suggestions?

I have the same question (0)
  • Suggested answer
    Jean Joel Kakou Profile Picture
    Microsoft Employee on at

    Hello Abhilash,  

    Quick question, where do you use this variable in your code: 

    Xrm.WebApi.retrieveRecord("sysdef_teammaster", TeamID, options).then(function success(result) {
    if (isNotNull(result.sysdef_role)) {
    console.log("sysdef_role: "+result.sysdef_role);
    var roleval=result.sysdef_role;

  • Community Member Profile Picture
    on at

    Hi Abhilash,

    Can you provide more detailed information or screenshot?

    What entity you are using?

    What option set field you want to based on?

    What lookup field you want to filter?

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 53 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans