Hi all,
I have a form that has three lookup fields on it. All three point to the users table. This form is created through a subgrid of a user record.
One field I null out so the person can choose what they want. But two fields I want to set.
User and Manager.
So today when the record is created through the subgrid both of these two lookups are populated with the users lookup info from the relationship. I dont see a way to tell it to auto populate the manager lookup. Seems like it just puts the user it is coming from into all user lookups. So javascript is what I guess I need to use to auto populate this. I've tried a million variations of this, but this is where I am at now. but when I run it the first alert comes back with "undefined". Not sure why though.
If anyone has some ideas for me on how to get this working I would appreciate it.
function setManager(executionContext) {
var formContext = executionContext.getFormContext();
var lookupValue = [{
id: "",
name: "",
entityType: "systemuser"
}];
var userId = formContext.getAttribute("new_user").getValue()[0].id.slice(1, -1);
if (userId !== null) {
Xrm.WebApi.retrieveRecord("systemuser", userId, "?$select=parentsystemuserid").then(
function success(result) {
var managerId = result.parentsystemuserid;
alert(managerId);
Xrm.WebApi.retrieveRecord("systemuser", managerId, "?$select=fullname").then(
function success(result) {
var managerName = result.fullname;
alert(managerName);
lookupValue[0].id = managerId;
lookupValue[0].name = managerName;
formContext.getAttribute("new_reportsto").setValue(lookupValue);
}
);
}
);
}
}