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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to delete file from file attribute in Dynamics 365 Sales using JavaScript

(0) ShareShare
ReportReport
Posted on by 5

I have a field of file type in Dynamics 365 Sales and requirement is to delete the uploaded file in that field using JavaScript. Can someone please help me with the code?

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    you can generate the JS code using Dataverse REST Builder, request type "Manage File Data", operation "Delete"

  • Suggested answer
    CRMJetty Profile Picture
    3,512 on at

    Hi PrakashJain,

    You can delete File from file type field using JS using ajax delete request.

    Here is the code:

    var requestUrl  = "https://[CRM_Domain]/api/data/v9.0/accounts(1519111b-5432-ed11-9db1-002248268032)/new_attachment";
    $.ajax({
    	type: "DELETE",
    	contentType: "application/json; charset=utf-8",
    	datatype: "json",
    	url: requestUrl,
    	async: false,
    	beforeSend: function (XMLHttpRequest) {
    		XMLHttpRequest.setRequestHeader("Accept", "application/json");
    		XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=*");
    	},
    	success: function (data, textStatus, XmlHttpRequest) {
    	   alert("Deleted successfully");
    	},
    	error: function (XMLHttpRequest, textStatus, errorThrown) {               
    		alert("error occured");
    	}
    });

    In request URL, after API URL, add entity plural name and entity record id in () after that add file type field logical name from which you want to delete file.
    pastedimage1663216979452v1.png

    You can create JS Web Resource with above code and use this WebResource as per your requirement i.e. form events, Ribbon buttons etc..

    I hope it helps,

    Thanks.

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Portal.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans