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 / Patch a multiple choic...
Power Pages
Answered

Patch a multiple choice column using ajax

(0) ShareShare
ReportReport
Posted on by 6
Hi,
I'm trying to create records in a dataverse table using ajax, as explained in this guide : Portals Web API write, update, and delete operations | Microsoft Learn
 
    (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)

	webapi.safeAjax({
		type: "POST",
		url: "/_api/accounts",
		contentType: "application/json",
		data: JSON.stringify({
			"name": "Sample Account"
		}),
		success: function (res, status, xhr) {
      //print id of newly created table record
			console.log("entityID: "+ xhr.getResponseHeader("entityid"))
		}
	});
 
I got everything working, except I can't figure out how to work with multiple choice fields. Any help ?
Categories:
I have the same question (0)
  • Verified answer
    DP_Prabh Profile Picture
    381 on at

    I’ve done something similar before. In my case, I needed to update a specific row and a specific column in the Account table, where the column was a multi-choice field. The following code worked for me.

     

    Code:

    var record = {};
    record.cr5d7_multicategory = "444200000,444200001";   // Choices 
    webapi.safeAjax({
        type: "PATCH",
        contentType: "application/json",
        url: "/_api/accounts(Record-GUID-ID)",     //add your GUID in parentheses
        data: JSON.stringify(record),
        success: function (data, textStatus, xhr) {
            console.log("Record updated");
        },
        error: function (xhr, textStatus, errorThrown) {
            console.log(xhr);
        }
    });
     
     
    I hope this works for you!
     
     
     
     
  • DB-31030832-0 Profile Picture
    6 on at
     
    I thought I had already tried that, but this time it worked. Thanks for the help !

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
11manish Profile Picture

11manish 38

#2
Valantis Profile Picture

Valantis 36

#3
omkarsupreme Profile Picture

omkarsupreme 24

Last 30 days Overall leaderboard