Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
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
Categories:
  • 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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans