How can i update the owner field using javascript?
*This post is locked for comments
Hi,
Please refer the links below.
stackoverflow.com/.../dynamics-crm-2015-update-opportunity-owner-id-via-javascript
rajeevpentyala.com/.../assign-record-using-jscript-in-crm-2011/
Hope this helps.
Hi
yes, if you want to get the value of the OwnerId (or other lookup field) have to do it like this
var ownerValue = Xrm.Page.getAttribute("ownerid").getValue();
if(ownerValue!=null)
{
console.log("OwnerId: " + ownerValue[0].id); // Ownerid: 0ebf407f-a255-46fd-b2a1-129d162751b8
console.log("OwnerName: " + ownerValue[0].name); // OwnerName: Test User
}
and if you want to set the ownerId value (or other lookup field) have to do it like this
Xrm.Page.getAttribute("ownerid").setValue([{ id: "0ebf407f-a255-46fd-b2a1-129d162751b8", name: "Test user", entityType: "systemuser" }]);
Everytime you set a lookup have in mind that the value (id) have to exists and the type (logical name of the entity) have to be the same of the relationship of the lookup
Regards
Thank you Sir,i just want to pick the lookup field and put or set that value into another look up field.
cant i just do it with simple JavaScript?
Hi shahzebkhanniet
if you what to change the owner of an entity record from the entity form you could do the following
//Assign record to current User
var UsedID = Xrm.Page.context.getUserId();
var UserName = Xrm.Page.context.getUserName();
Xrm.Page.getAttribute("ownerid").setValue([{ id: UsedID, name: UserName, entityType: "systemuser" }]);
Xrm.Page.data.save()
If you what to change the owner of a record different to the one you are working with you could create an Action and attach a plugin to it and search for the record and assign it (or do whatever you want)
ansrikanth.com/.../execute-multiple-operations-with-single-service-call-from-client-crm-webapi-using-custom-actions
Hope it helps
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Aric Levin - MVP 2 Moderator
HR-09070029-0 2
MA-04060624-0 1