2

I'm trying to update number fields to hold only 1 decimal place but I can't seem to do this through REST.

I tried Pnp Js but it's not working, there's no error, it just doesn't update:

pnp.sp.web.lists.getByTitle("Risks").fields.getByInternalNameOrTitle('ImpactCost').update({
    DisplayFormat: 4
}, 'SP.FieldNumber')

1 Answer 1

1

I'm able to update number field with decimal point using REST API. Below is my rest code. should help.

function updateListItem() {          
            var formdigestValue = $("#__REQUESTDIGEST").val();
            var webUrl = _spPageContextInfo.webAbsoluteUrl;
            var updateMetadata = { __metadata: { 'type': "SP.Data.TestlistListItem" }, 'numberfld': 10.888 };          
            $.ajax
            ({
                url: webUrl + "/_api/web/lists/getByTitle('Testlist')/items(1)",
                type: "POST",
                data: JSON.stringify(updateMetadata),
                headers:
                {
                    "Accept": "application/json;odata=verbose",                    
                    "X-RequestDigest": formdigestValue,
                    "IF-MATCH": "*",
                    "content-type": "application/json;odata=verbose",
                    "X-HTTP-Method": "MERGE"
                },

                success: function (data, status, xhr) {
                    console.log("number updated");                    
                },
                error: function (data,xhr, status, error) {
                    console.log("Error While Updating: " + data.responseJSON.error);                        
                }
            });

        }

Change type attribute (SP.Data.TestlistListItem) in metadata with your list category term & change column name(numberfld).

NOTE: In case, If you are trying to update number as decimal point preceding with zeros (10.00) then field will automatically round it as whole number(10).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.