Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Copying owner value in custom field

Posted on by 760

Hi, 

I'm trying to copy the value of the owner in my custom field so I can manipulate it. I tried using javascript but it did not work.I wanted to use the calculated fields instead but they have different data type. Is there a chance I create a field with owner data type?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Copying owner value in custom field

    Hi Arci,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Copying owner value in custom field

    Are you talking about Lead Source field (option set)?

    Basically the easiest way is to handle this via a workflow.

    Create a workflow on the Create of a new Lead, and add a check condition for a particular field.

    If the condition of that is true, then Update the lead record Source.

    You should do this on a different field rather than Owner (SYSTEM is a little problematic using Workflows).

    If you need, you can add a field to the Web Form, so that it is displayed in the Portals.

  • CRMexplorer Profile Picture
    CRMexplorer 760 on at
    RE: Copying owner value in custom field

    when the lead came from the portal I wanted to set the source automatically to "online". I thought I can use the owner field since it automatically changes to "SYSTEM"

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Copying owner value in custom field

    What field exactly are you trying to set the owner id field to?

    Based on your code above it is campaign id.

    The campaign id data type is neither systemuser or team.

    Also, campaign id must accept Guid data type and not a string.

  • CRMexplorer Profile Picture
    CRMexplorer 760 on at
    RE: Copying owner value in custom field

    Hi Ivan,

    I can copy the owner via alert but not in the field

    function setl()

    {

    var owner = Xrm.Page.getAttribute("ownerid").getValue()[0];

    var ownerId = owner.id;

    var ownerName = owner.name;

    var ownerType = owner.entityType;

    SetLookupValue("'campaignid", ownerId, ownerName, ownerType )

    if(ownerName=="SYSTEM")

    {

    alert(ownerId);

    Xrm.Page.getAttribute('campaignid').setValue("Online Inquiry");

    }

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Copying owner value in custom field

    Yes, that's right.

    So the code will be:

    var ownerType = owner.entityType;

    if(ownerType == "systemuser")

    {

         Xrm.Page.getAttribute("new_fieldforsystemusertype").setValue(Xrm.Page.getAttribute("ownerid"));

         // or SetLookupValue("new_fieldforsystemusertype", ownerId, ownerName, "systemuser");

    }

    else if(ownerType == "team")

    {

       Xrm.Page.getAttribute("new_fieldforsystemteamtype").setValue(Xrm.Page.getAttribute("ownerid"));

         // or SetLookupValue("new_fieldforsystemteamtype", ownerId, ownerName, "team");

    }

    Please let us know.

    Greetings

    Francesco Picchi

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Copying owner value in custom field

    Can't we just use

    Xrm.Page.getAttribute(fieldName).setValue(Xrm.Page.getAttribute("ownerid")) ?

    Although, I think part of the problem is that ownerid can be of two different entity types:

    "SystemUser" or "Team"

    In that sense, Arci might need two different fields (one for the team owners, and another one for the user owners)

  • Ivan Ficko Profile Picture
    Ivan Ficko 1,380 on at
    RE: Copying owner value in custom field

    Oh, thanks for the correction. I just forgot at the moment of typing that there is entityType attribute in lookup item. That's what you get when you code without trying the code in the console.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Copying owner value in custom field

    Using this code you could pass directly the owner type of "owner" variable, like:

    var ownerType = owner.entityType;

    SetLookupValue("new_yourfieldname", ownerId, ownerName, ownerType )

    Please let us know.

    Greetings

    Francesco

  • Suggested answer
    Ivan Ficko Profile Picture
    Ivan Ficko 1,380 on at
    RE: Copying owner value in custom field

    First, you need to get owner value by executing:

    var owner = Xrm.Page.getAttribute("ownerid").getValue()[0];
    var ownerId = owner.id;
    var ownerName = owner.name;

    You need to be careful when passing the entityType parameter to function below. This parameter must be entity name (eg. "systemuser"), not the type you get by executing upper code (eg. "8").

    You can use this function to set lookup value:

    function SetLookupValue(fieldName, id, name, entityType) {
        if (fieldName != null) {
            var lookupValue = new Array();
            lookupValue[0] = new Object();
            lookupValue[0].id = id;
            lookupValue[0].name = name;
            lookupValue[0].entityType = entityType;
            if (lookupValue[0].id != null) {
                Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
            }
        }
    }


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans