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?
Solved! Go to Solution.
@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!
try to simplify the code:
formContext.getAttribute("ownerid").setValue([{
id: "cec4bd48-df38-eb11-a813-000d3a531257",
name: "Child Business Unit 1",
entityType: "team"
}]);
Can you please provide the screenshot of an error you experience?
Can you please provide the screenshot of the team record you use in your code?
Can you confirm that the team you mentioned has a security role to own the record you want to update?
I had the same thought as @a33ik , and even thought at using
Xrm.Page.getAttribute("ownerid").setValue([{id: "{CEC4BD48-DF38-EB11-A813-000D3A531257}", entityType: "team"}])
since the sdk is saying the id should be like this {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
But I've tried out, and my test didn't work.
If the security is not right, the error should come later, when trying to save, not when we simply calling the setValue. Also the "Assign" button wouldn't work.
The Lookup.getEntityTypes returns only "systemuser", and I couldn't succeed to change it
I suppose it's a bug.
Now, this doesn't help you @tschopp , except to know that you are not alone ...
Kind regards,
Diana
I also know that it's not security because I can use the Assign tool from the ribbon to set the owner to that Team after saving the record. But I don't want users to have to do that. Unless you have other ideas, I will submit a support request to Microsoft.
I can confirm the exact same issue on my end. Users can be set as owners with javascript but not teams. Been having this issue for weeks. I even manually set the owner to the admin team and used console.log(formContext.getAttribute("ownerid").getValue()) to make sure I was building the array correctly, and I still receive the same error:
Uncaught (in promise) UciError: Value should be of type: entityType: Parameter Name: value[0].entityType
Starting think it is a bug as I have tried pretty much everything.
@ferris - Thanks for the confirmation. I have a support ticket open with MS Support. I will let you know what the resolution is.
Thanks man, it's driving me nuts
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");
}
);
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.