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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Update Owner field

(0) ShareShare
ReportReport
Posted on by

How can i update the owner field using javascript?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Update Owner field

    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.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Update Owner field

    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

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Update Owner field

    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?

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Update Owner field

    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

    Regards

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans