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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Update field value wit...
Power Pages
Unanswered

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard