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 / Update field value wit...
Power Pages
Answered

Update field value with web api retrun 400 bad request when the origional value is null

(0) ShareShare
ReportReport
Posted on by 15

I want to update the table fields through web api according to the following site.

How to: Use the portal Web API | Microsoft Learn

The following code works well when the origional value is not null, but when the origional value is null, the request returns 400 bad request. 

 

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;
 }

 

 So how can I update the field value when the origional value is null?

Categories:
I have the same question (0)
  • Akah Mandela Profile Picture
    445 on at

    You could update your function to handle null values as follows 

    function updateRecordAttribute(col, recordObj) {
     var attributeName = col.name,
     value = recordObj[attributeName],
     newValue = prompt("Please enter \"" + col.label + "\"", value);
    
     if (newValue !== null) {
     // Only proceed if newValue is not null
     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);
     }
     });
     } else {
     // Handle null value (e.g., display a message or take alternative action)
     console.log("New value is null. No update performed.");
     }
     return false;
    }
  • Harvin Profile Picture
    15 on at

    Thank you for your reply, but my case is the original value is null, not the new value is null.

  • Akah Mandela Profile Picture
    445 on at

    Then you should also check if the original value is null and do the update 

    function updateRecordAttribute(col, recordObj) {
     var attributeName = col.name,
     value = recordObj[attributeName],
     newValue = prompt("Please enter \"" + col.label + "\"", value);
    
     if (newValue !== null || value == null) {
     // Only proceed if newValue or value is not null
     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);
     }
     });
     } else {
     // Handle null value (e.g., display a message or take alternative action)
     console.log("New value is null. No update performed.");
     }
     return false;
    }
  • Harvin Profile Picture
    15 on at

    Sorry, my requirement is updating the null value to expected value, not skip.

  • Verified answer
    Harvin Profile Picture
    15 on at

    Sorry, it's my mistake, the codes have no problem. The reason of the error is that my "newValue" become null.

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 64

#2
DP_Prabh Profile Picture

DP_Prabh 34

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 30 Most Valuable Professional

Last 30 days Overall leaderboard