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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Portals Web API - Issu...
Power Pages
Unanswered

Portals Web API - Issue with PUT Request for currency field

(0) ShareShare
ReportReport
Posted on by 38

I am testing using the Web API to update a currency field using a PUT request as per here. I am using the following sample code provided by Microsoft. This works fine when the field being updated is a string, however results in an 'Error:Common Data Service error occurred' for a currency field. I believe that this is because newValue is sent with quotes e.g. "999".

How can I amend the below code to allow for currency fields?

 

function updateRecordAttribute(col, recordObj) {
   var attributeName = col.name,
        value = recordObj[attributeName],
        newValue = prompt("Please enter \"" + col.label + "\"", value);
  if (newValue != null && newValue !== value) {
      appAjax('Updating...', {
           type: "PUT",
           url: "/_api/contacts(" + recordObj.id + ")/" + attributeName,
           contentType: "application/json",
           data: JSON.stringify({
            "value": newValue
            }),
            success: function (res) {
            table.updateRecord(attributeName, newValue, recordObj);
            }
   });
}
return false;
}

 

Thanks in Advance

Categories:
I have the same question (0)
  • ragavanrajan Profile Picture
    7,044 Most Valuable Professional on at

    Hi @AInglis , 

     

           When updating currency column, can you try calling its associate column with _base on it. Ex: annualincome is currency column, annualincome_base is where the value is stored.  Screenshot below. 

     

    ragavanrajan_0-1612393290972.png

    Not tried it personally but thinking if you call the _base column which holds the actual value on it. 

     

    If not the workaround may be: 

     

    1. Create a string column and use your web api to PATCH request on the new column 

    2. Using Power Automate > CDS > Trigger will be "When item is created or modified" then take the value and update it to relevant currency column. 

     

    I know it is tough workaround but I think will help you some way. 

     

    Hope it helps. 

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    Webapi with currency field works for me with both PUT and Patch

     

    Using the Wrapper Ajax Function (also in the link you provided), and the Site Settings include the entity and field to allow the Webapi access

     

    xxx_price is a currency field (itemId is a vaiarble containing a record guid obtained elsewhere)
    
    webapi.safeAjax({
     type: "PUT",
     url: "/_api/xxx_xxxxxs("+itemId+")/xxx_price",
     contentType: "application/json",
     data: JSON.stringify({
     "value": 77.77
     }),
     success: function (res) { 
     console.log(res);
     }
     });
    
     webapi.safeAjax({
     type: "PATCH",
     url: "/_api/xxx_xxxxxs("+itemId+")",
     contentType: "application/json",
     data: JSON.stringify({
     "xxx_price": 99.99
     }),
     success: function (res) { 
     console.log(res);
     }
     });

     

  • ragavanrajan Profile Picture
    7,044 Most Valuable Professional on at

    Thanks @Fubar , quick question. Did you load the web api safe ajax function as a snippet or in javascript? 

  • AInglis Profile Picture
    38 on at

    Thanks @Fubar ,

    I am trying to adapt the code example from step 14 here.  The function updateRecordAttribute is used for all the columns.

    In the example all the columns are strings so it works fine, however when I use it against my custom entity with currency fields it won't update.

     

    The prompt variable newValue = prompt("Please enter \"" + col.label + "\"", value) returns "250.00" not 250.00 which gets rejected by the API.

     

    Is there a way to use this function so that it returns "250.00" for string fields and 250.00 for currency fields.

    Thanks

     

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    @ragavanrajanat the moment I have it embedded in script tags in a custom Web Template.  I am just putting something together and if it does what I want, will then separate somethings out a bit more.

     

    @AInglisyou can convert string to number in JavaScript using the standard JavaScript function parseFloat(<string>)  

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 17 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 12

#2
CN-06091549-0 Profile Picture

CN-06091549-0 12

Last 30 days Overall leaderboard