Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Option set value from account to lead on parent account for lead selection

(0) ShareShare
ReportReport
Posted on by 55

HI Everyone 

I am new to development and trying to get option set value from account to lead on existing account selection but my JS is not working , can any one suggest what is the mistake here:

function retrieveData(executionContext) {
debugger;
var formcontext = executionContext.getFormContext();
var accountId = formcontext.getAttribute("parentaccountid").getValue();




if (accountId != null) {

Xrm.WebApi.retrieveRecord("account", accountId[0].id, "?$select=name,ownershipcode").then(
function success(result) {


var accountOwner = result("ownershipcode@OData.Community.Display.V1.FormattedValue");
formcontext.getAttribute("new_ownership").setValue(accountOwner);


},
function (error) {
console.log(error.Message);
}

);
}

}

  • RE: Option set value from account to lead on parent account for lead selection

    Thank you all it worked

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Option set value from account to lead on parent account for lead selection

    Hi Beginner Developer,

    Please try Bipin Kumar's code. It could work on my side. Just pay attention to one thing. The items' value of the new ownership field on lead entity should be the same with that field on account entity.

    Something like these screenshots:

    Ownership on the Account table:

    pastedimage1652160219906v2.png

    Custom field on the Lead entity:

    pastedimage1652160350336v3.png

    Below is my test:

    Set-Ownership.gif

  • RE: Option set value from account to lead on parent account for lead selection

    Thank you Guido!

    Yes , both are option set only

    but not populating any value

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: Option set value from account to lead on parent account for lead selection

    Hi,

    Try below code

    function retrieveData(executionContext) {

    debugger;

    var formcontext = executionContext.getFormContext();

    var accountId = formcontext.getAttribute("parentaccountid").getValue();

    if (accountId != null) {

    Xrm.WebApi.online.retrieveRecord("account", accountId[0].id, "?$select=name,ownershipcode").then(

    function success(result) {

    var ownershipcode = result["ownershipcode"]; // Choice

    formcontext.getAttribute("new_ownership").setValue(ownershipcode);

    },

    function(error) {

    console.log(error.message);

    }

    );

    }

    }

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,073 Moderator on at
    RE: Option set value from account to lead on parent account for lead selection

    main problem is the syntax on how you retrieve the value, you should use square brackets, so code will be

    var accountOwner = result["ownershipcode@OData.Community.Display.V1.FormattedValue"];

    second is the type of the field new_ownership, because you are setting the text of the ownershipcode right now, if is an optionset too (with the same values or not) change the way to set the field and the value to fetch (not gettting the formattedvalue but just the value)

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans