I'm trying to update the OwnerId on an opportunity in Dynamics CRM 2015.
So far I am using the following code but my changes are not taking effect.
Xrm.Page.data.entity.attributes.get('ownerid').setValue('487ecd0c-d8c1-e411-80eb-c4346bade4b0')
Xrm.Page.data.entity.save();
This is a view of the GetValue call.
The attribute type is "lookup" and when I call getIsDirty(), it returns false after I do setValue, so I'm not sure if that's the correct way to set the value on a "lookup" type.
Owner
is a special field, it can be changed only with an AssignRequest
.
With CRM Online Update 1 this changed, special fields like Owner
or StateCode
can be updated with an update request, but as far as I know this is valid from server side, for client side changes you will still need to use an AssignRequest
.
Here a sample code:
EDIT: Just for reference, this is the way to set a lookup field
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = '{487ecd0c-d8c1-e411-80eb-c4346bade4b0}';
lookup[0].name = 'Test Account';
lookup[0].entityType = 'account';
Xrm.Page.getAttribute("new_account").setValue(lookup);
or short version
Xrm.Page.getAttribute("new_account").setValue([{ id: '{487ecd0c-d8c1-e411-80eb-c4346bade4b0}', name: 'Test Account', entityType: 'account'}]);