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?