Introduction: Here is JavaScript code that you can use to make the required attendee field show only system user records and also in case you have a requirement to the set the owner of record as default required attendee refer code below.
Solution:
Add below function to your web resource on load event of add.
filterrequiredattenees: function (exec Context)
{
var formContext = execContext.getFormContext();
formContext.getControl("requiredattendees").setEntityTypes(["systemuser"]); //filter the required attendees to show only records from system user entity.
if (formContext.getAttribute("ownerid").getValue() != null)
{
ownerid = formContext.getAttribute("ownerid").getValue()[0].id.replace("{", "").replace("}", ""); // remove the brackets from ownerid
var value = new Array();
value[0] = new Object();
value[0].id = ownerid; // owner id value
Xrm.WebApi.retrieveRecord("systemuser", ownerid, "?$select=fullname").then(
function success(data)
{
// here we retrieve the owner name, the value object needs id, name and entity type parameter.
name = data.fullname;
value[0].name = name;
value[0].entityType = "systemuser";
formContext.getAttribute("requiredattendees").setValue(value); // set the owner as Require attendee
},
function (error) {
Xrm.Utility.alertDialog(error.message);
})
}
}
On load of form the Required attendee will be owner of record and we can add new attendee easily as the dropdown will show only user records.
Instead of users, if you need contact records, just change the set entity type->
formContext.getControl("requiredattendees").setEntityTypes(["contacts"]);
Comments
Post a Comment