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 Apps / How to update a field ...
Power Apps
Unanswered

How to update a field of datatype of File or Image

(0) ShareShare
ReportReport
Posted on by 293

I am building a PCF for a custom page and one of the controls is an input that allows a user to upload a file attachment to a column of datatype file.

I feel like there is more than one step in updating the database with the file content because the following does not work.

 

 

 const fileString = {
 slp_file: {
 fileContent:
 "PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg0KPHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHN0cm9rZT0iYmxhY2siIGZpbGw9InJlZCIgc3Ryb2tlLXdpZHRoPSIwIi8+DQo8L3N2Zz4=",
 fileName: "Square_Red_16x16.svg",
 fileSize: 215,
 mimeType: "image/svg+xml",
 },
 };

const newRecord = Xrm.WebApi.updateRecord(this.resultItem.logicalName, this.id, fileString).then(
 (r) => r,
 (e) => console.log(e),
 );
 };

 

 

 I keep getting the following error.

 

 

 1: An error occurred while validating input parameters: Microsoft.OData.ODataException: An unexpected 'StartObject' node was found for property named 'slp_file' when reading from the JSON reader. A 'PrimitiveValue' node was expected. 

 

Is there a table like fileattachment to create the file first and then associate the link to this record to the actual field in my table?

Does anyone know what steps I should take to save the selected file to the database to a field that has datatype or "File" or "Image".

 

I have the same question (0)
  • Guido Preite Profile Picture
    1,490 Super User 2024 Season 1 on at

    If the column is Image you can update the image using the base64 encoded value directly as a property, for example:

    var record = {};
    record.sample_image = ""; // Base 64 Image
    
    Xrm.WebApi.online.updateRecord("sample_customtable", "", record).then(
    	function success(result) {
    		var updatedId = result.id;
    		console.log(updatedId);
    	},
    	function(error) {
    		console.log(error.message);
    	}
    );

    for a File column I am not aware of an Xrm.WebApi method compatible, because the content needs to be set as binary and just updating that specific property, you can do with a Fetch o jQuery but not with Xrm.WebApi

    you can use my tool Dataverse REST Builder if you need to create such queries

  • KASCHN Profile Picture
    293 on at

    @GuidoPreite Thank you so much. Yes this worked for an image datatype column. The file datatype column is still a mystery to me. Obviously, the column is looking for a reference to a file. I think it is more of a lookup column. What I can't figure out is which table I would use to store the file and then reference in my file datatype column. Would it be any of these tables?

    •     "fileattachment",
    •     "msdyn_richtextfile",
    •     "activityfileattachment",
  • Guido Preite Profile Picture
    1,490 Super User 2024 Season 1 on at

    File column contents are not stored inside Dataverse, so you will not find a table hosting that information.

    As I wrote before there isn't (afaik) a direct Xrm.WebApi method to upload a content to a file column.

  • KASCHN Profile Picture
    293 on at

    Thank you again. I am leaving this open a bit longer as I am still researching. There is now the setValue() method on a dataset record that will accept a file object. I took the "afaik" (as far as I know?) comment to mean that I can remain hopeful. 

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 Apps

#1
Valantis Profile Picture

Valantis 387

#2
timl Profile Picture

timl 340 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 301

Last 30 days Overall leaderboard