Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Presearch filter based on Option Set attribute value using js

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?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Presearch filter based on Option Set attribute value using js

    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.

  • Suggested answer
    RE: Presearch filter based on Option Set attribute value using js

    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;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans