web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can't set record owner...
Power Apps
Unanswered

Can't set record owner to a Team

(3) ShareShare
ReportReport
Posted on by 311

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?

 

 

I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    try to simplify the code:

    formContext.getAttribute("ownerid").setValue([{
    	id: "cec4bd48-df38-eb11-a813-000d3a531257",
    	name: "Child Business Unit 1",
    	entityType: "team"
    }]);
  • tschopp Profile Picture
    311 on at

    @a33ik - I just tried your idea and I'm getting the same error.

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    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?

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @a33ik , Hi @tschopp , 

     

    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

    DianaBirkelbach_0-1624299729953.png

    I suppose it's a bug.

    Now, this doesn't help you @tschopp , except to know that you are not alone ...

    Kind regards,

    Diana

  • tschopp Profile Picture
    311 on at

    @a33ik @DianaBirkelbach 

    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.

  • ferris Profile Picture
    42 on at

    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.

  • tschopp Profile Picture
    311 on at

    @ferris - Thanks for the confirmation.  I have a support ticket open with MS Support.  I will let you know what the resolution is.

  • ferris Profile Picture
    42 on at

    Thanks man, it's driving me nuts

  • cchannon Profile Picture
    4,702 Moderator on at

    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");
     }
    );

     

  • tschopp Profile Picture
    311 on at

    @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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard