cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tschopp
Advocate III
Advocate III

Can't set record owner to a Team

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
tschopp
Advocate III
Advocate III

@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!

View solution in original post

17 REPLIES 17
a33ik
MVP

try to simplify the code:

formContext.getAttribute("ownerid").setValue([{
	id: "cec4bd48-df38-eb11-a813-000d3a531257",
	name: "Child Business Unit 1",
	entityType: "team"
}]);
tschopp
Advocate III
Advocate III

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

a33ik
MVP

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?

DianaBirkelbach
Super User
Super User

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

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
tschopp
Advocate III
Advocate III

@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
Helper I
Helper I

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
Advocate III
Advocate III

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

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Kudoed Authors
Users online (2,874)