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 / Updating a choice fiel...
Power Pages
Unanswered

Updating a choice field using web api

(0) ShareShare
ReportReport
Posted on by 125

Hi, I am trying to update a choice field using the web api but keep getting error.

 

My table has a column 'new_levels' and i want the user to be able to update this field from a dropdown.  I have the dropdown working correctly but when I try the put it keeps giving errors and I am not sure why.  I had a similar issue with a yes/no field ...to solve this i change their values to true/false instead of yes/no and it work...so i tried to change values of my choice to 100000000, etc but it still wont accept the update.

 

error shows

 
  1. Request Method:
    PATCH
  2. Status Code:
    404 Not Found
  3.  
    Referrer Policy:
    strict-origin-when-cross-origin

Payload {new_level: "100000001"}

new_level: "100000001"

 

(function(webapi, $){
        function safeAjax(ajaxOptions) {
            var deferredAjax = $.Deferred();
    
            shell.getTokenDeferred().done(function (token) {
                // add headers for ajax
                if (!ajaxOptions.headers) {
                    $.extend(ajaxOptions, {
                        headers: {
                            "__RequestVerificationToken": token
                        }
                    });
                } else {
                    ajaxOptions.headers["__RequestVerificationToken"] = token;
                }
                $.ajax(ajaxOptions)
                    .done(function(data, textStatus, jqXHR) {
                        validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
                    }).fail(deferredAjax.reject); //ajax
            }).fail(function () {
                deferredAjax.rejectWith(this, arguments); // on token failure, pass the token ajax and args
            });
            return deferredAjax.promise();  
        }
        webapi.safeAjax = safeAjax;
})(window.webapi = window.webapi || {}, jQuery)

//custom code
var globalArray = [];

function pushArray(currentObject) {
var str = currentObject.id;
var res = str.split("|");
var capId = res[1];
var checkbox = document.getElementById("id|" + capId).checked;
var levelvalue = document.getElementById("level|" + capId);
var level = levelvalue.options[levelvalue.selectedIndex].value
console.log(level)

 
if( level == '0 - None'){
level = "100000000";
}
if( level == '1 - Trained (Only)'){
level = "100000001";
}
if( level == '2 - Capable'){
level = "100000002";
}
if( level == '3 - Capable/Certified'){
level = "100000003";
}
 
// }
console.log(level);

let objIndex = globalArray.findIndex((obj => obj.id == capId));
if (objIndex == -1) {
globalArray.push({
id: capId,
level: level,
 
checkboxval: checkbox
})
} else {
globalArray[objIndex].level = level;
 
globalArray[objIndex].checkboxval = checkbox;
}
}

function pushArrayCheckBox(currentObject) {
var str = currentObject.id;
var res = str.split("|");
var capId = res[1];
var checkbox = document.getElementById("id|" + capId).checked;
 
var value = document.getElementById("level|" + capId);
var level = value.options[value.selectedIndex].value;
if( level == '0 - None'){
level = "100000000";
}
if( level == '1 - Trained'){
level = "100000001";
}
if( level == '2 - Capable'){
level = "100000002";
}
if( level == '3 - Capable/Certified'){
level = "100000003";
}
 
let objIndex = globalArray.findIndex((obj => obj.id == capId));
if (objIndex == -1) {
globalArray.push({
id: capId,
 
checkboxval: checkbox,
level:level
})
} else {
 
globalArray[objIndex].checkboxval = checkbox;
globalArray[objIndex].level = level;
}
}

function update() {
var i;
for (i = 0; i < globalArray.length; i++) { //update checked row changes
alert( globalArray[i].level + "-" + globalArray[i].checkboxval );
if (globalArray[i].checkboxval == true) //true
{
document.getElementById("processingMsg").innerHTML = "Processing....";
try {
let value = {
 
"new_capabilitylevel": globalArray[i].level
};
webapi.safeAjax({
type: "PATCH",
url: "/_api/new_capabilitieses(" + globalArray[i].id + ")",

contentType: "application/json",
data: JSON.stringify(value),
success: function(res) {
document.getElementById("processingMsg").innerHTML = "Records updated successfully.";
}
});
 
}
catch (e) {
alert(e.message);
}
}
}

 
//refresh();

}

 

 

Categories:
I have the same question (0)
  • MH-02091453-0 Profile Picture
    125 on at

    never mind - just realised I hadn't added site settings for the entity...fixed now 🙂

     

    😂

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Valantis Profile Picture

Valantis 49

#2
11manish Profile Picture

11manish 33

#3
Haque Profile Picture

Haque 28

Last 30 days Overall leaderboard