In my model-driven app, I have a form for a custom entity that has a lookup field and the owner field on it. When adding a new record, the owner defaults to the current user. When a value is selected in the lookup field, I'm trying to get the owner value from the selected lookup value and set the owner of the record I'm adding to that value. If the owner value is a User, it works fine. But when the owner is a Team, I get the following error:
Uncaught (in promise) UciError: Value should be of type: entityType: Parameter Name: value[0].entityType
Here is my code that's executed in the onChange JavaScript event (with variable values hardcoded so you can see what they are):
ownerId = "cec4bd48-df38-eb11-a813-000d3a531257";
teamName = "Child Business Unit 1";
entityType = "team";
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = ownerId;
lookupItem.name = teamName;
lookupItem.entityType = entityType;
lookupData[0] = lookupItem;
var fieldOwner = formContext.getAttribute("ownerid");
fieldOwner.setValue(lookupData);
I also noticed that on the UI, if I click in the owner field, I can only search for users. But using the Assign feature, I can assign it to this Team. Is there another setting that I need to change to be able to set it to a Team in Javascript?
Ok good to hear! Will do that as soon as I get back to working on the app. Never even considered the need to do it with core default entities, but it makes sense.
@a33ik @ferris @cchannon @DianaBirkelbach
MS support found the solution for us. You have to add the Team entity to the list of entities in your App. Once I added it to mine, the Owner lookup field in the UI allows for the selection of a Team, and they JavaScript code can set it to a Team value as well. Thank you to Shiva Gandikota at Microsoft Support!
Tried it both ways (with and without brackets). I do believe the brackets are correct though, try console.log on an existing owner and it will include the brackets. You just don't want to include them with your queries. Though I could be missing something, still consider myself new to Powerapps WebAPI.
Well, you don't want the brackets in your id, but that is probably a downstream issue.
Tried it again this morning looking at your code cchannon. Rewrote what I had, very dumbed down version, still doesn't work. I can confirm it works for users but not teams. Furthermore, it appears that I cannot select a team or business unit within a form as owner. I can, however, do a mass edit by selecting multiple records from the main grid, and this allows me to set teams as owners. I wonder if the issues related? Here is the dumbed down code:
function SetAdminOwner(executionContext) {
var formContext = executionContext.getFormContext();
var owner = [{ entityType: "team", id: "{52CEBC12-4550-EB11-A813-000D3A3263E5}", name: "Administration" }]
formContext.getAttribute("ownerid").setValue(owner);
}
Running in Edge:
@cchannon - Just tried your code and getting the same error when entityType = "team":
Uncaught (in promise) UciError: Value should be of type: entityType: Parameter Name: value[0].entityType
Works fine for some code I have running. The example below is pulling the owner from a related record to populate the current record owner and it works fine for Team or User:
Xrm.WebApi.retrieveRecord(record.entityType, record.id, "?$select=new_name&$expand=owninguser($select=systemuserid, fullname), owningteam($select=teamid, name)").then(
function success(result) {
var owningTeam = result.owningteam;
var owningUser = result.owninguser;
if (owningUser !== null) {
var ownerId = owningUser.ownerid;
var ownerName = owningUser.fullname;
var owner = [{ entityType: "systemuser", id: ownerId, name: ownerName }]
}
else if (owningTeam !== null) {
var ownerId = owningTeam.ownerid;
var ownerName = owningTeam.name;
var owner = [{ entityType: "team", id: ownerId, name: ownerName }]
}
formContext.getAttribute("ownerid").setValue(owner);
},
function (error) {
var message = "Whoopsies!";
formContext.ui.setFormNotification(message, "WARNING", "error");
}
);
Thanks man, it's driving me nuts
WarrenBelz
87
Most Valuable Professional
mmbr1606
71
Super User 2025 Season 1
Michael E. Gernaey
65
Super User 2025 Season 1