Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

retrieve "transactioncurrencyid" from parent "opportunity"

Posted on by 448
Hi all
I'm trying to retrieve the /transactioncurrencyid/ from parent /opportunity/.
This is my Javascript lines:
        var strValuta = parent.Xrm.Page.getAttribute(/transactioncurrencyid/).getValue();
        var formattedCurrencyId = strValuta[0].id;
        var formattedCurrencyName = strValuta[0].name;
        alert(strValuta + / - / + formattedCurrencyId + / - / + formattedCurrencyName);

In my parent opportunity the currency is CHF but in the alert I retrieve the EUR that is not correct.
Can somebody correct my javascript or suggest me some alternate idea to retrieve the correct currency in my child table?
Thanks in advance
  • DiePic Profile Picture
    DiePic 448 on at
    retrieve "transactioncurrencyid" from parent "opportunity"
    now it's working .... thank you very much Leah Ju
  • Verified answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    retrieve "transactioncurrencyid" from parent "opportunity"
    Hi ,
    The image is not loading.
    You are trying to update the 'transactioncurrencyid' value on the child table, right?
    This is one lookup column, you need set it's value with id, name and entity type.
    It should be like:
            Xrm.WebApi.retrieveRecord("opportunity", opportunityID, "?$select=_transactioncurrencyid_value").then(
                    function success(result) {
                            console.log(result);
                            // Columns
                            var opportunityid = result["opportunityid"]; // Guid
                            var transactioncurrencyid = result["_transactioncurrencyid_value"]; // Lookup
                            var transactioncurrencyid_formatted = result["_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue"];
                            var transactioncurrencyid_lookuplogicalname = result["_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
    
                            var lookup = [];
                            lookup[0] = {};
                            lookup[0].id = transactioncurrencyid;
                            lookup[0].entityType = transactioncurrencyid_lookuplogicalname;
                            lookup[0].name = transactioncurrencyid_formatted;
    
                            // Get and Set New Lookup
                            formContext.getAttribute("transactioncurrencyid").setValue(lookup);
                    },
                    function (error) {
                            console.log(error.message);
                    }
            );
     
     
     
  • DiePic Profile Picture
    DiePic 448 on at
    retrieve "transactioncurrencyid" from parent "opportunity"
    Hi  Leah Ju   and thanks for the reply.
    It's exactly what I was looking for.
    Now with this javascript
            if (!strNumOpportunita) {
              formContext.getAttribute("ath_name").setValue(NumOpportunita);
              formContext.getAttribute("transactioncurrencyid").setValue([{ id: strValuta, entitàType: "transactioncurrency" }]);
            }

     
    my value columns are correct, but how can I also change the name of the exposed "value" field?

    ​​​​​​​
  • Verified answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    retrieve "transactioncurrencyid" from parent "opportunity"
    Hi,
    Your description: from parent /opportunity...in my child table..
    Will this parent opportunity be a lookup field on a child table?
    If so, you can get opportunity id, then use this id to retrieve this record to get transactioncurrencyid value.
    Please refer to this example code
    function getOpportunityCurrency(executionContext) 
    {
            var formContext = executionContext.getFormContext();
            var opportunityID = formContext.getAttribute("opportunityid")[0].id;
    
    
            Xrm.WebApi.retrieveRecord("opportunity", opportunityID, "?$select=_transactioncurrencyid_value").then(
                    function success(result) {
                            console.log(result);
                            // Columns
                            var opportunityid = result["opportunityid"]; // Guid
                            var transactioncurrencyid = result["_transactioncurrencyid_value"]; // Lookup
                            var transactioncurrencyid_formatted = result["_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue"];
                            var transactioncurrencyid_lookuplogicalname = result["_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
    
                            alert("");
                    },
                    function(error) {
                            console.log(error.message);
                    }
            );
    
    }

    I hope you can mark my answer verified if it answer your question! If you have any questions, please feel free to contact me.
    Regards,
    Leah

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans