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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Client-side: Need to check the file name & extension of Field Type = Field

(0) ShareShare
ReportReport
Posted on by 2,822

Hello Everyone,

Thanks for reading my question.

I've created a Field of type File and place it on the form. I need to do basic validation of the file such as File extension and File content. Now, with the help of Dataverse REST Builder I've the code to find the file name/extension & file content but the challenge is if I run the code on the fieldOnChange then the needed information doesn't exist in the database by the time. So, I need to find some other event on which I can trigger the code.

4530.FileOnChange.png

this.fileToProcessOnChange = function(executionContext){ 
    prg_DataTransfer.checkFileExtension(executionContext);
}

this.checkFileExtension = function (executionContext){
    $.ajax({
        type: "GET",
        url: Xrm.Utility.getGlobalContext().getClientUrl()   "/api/data/v9.2/prg_temporarydatas(cfb732f7-7acd-4193-9bfc-d4b352669f1c)?$select=prg_filetoprocess_name",
        headers: {
            "OData-MaxVersion": "4.0",
            "OData-Version": "4.0",
            "Content-Type": "application/json; charset=utf-8",
            "Accept": "application/json",
            "Prefer": "odata.include-annotations=*"
        },
        async: true,
        success: function (data, textStatus, xhr) {
            var result = data;
            //console.log(result);
            // Columns
            var prg_temporarydataid = result["prg_temporarydataid"]; // Guid
            var prg_filetoprocess_name = result["prg_filetoprocess_name"]; // Text
            console.log("File Name: "   prg_filetoprocess_name);
        },
        error: function (xhr, textStatus, errorThrown) {
            console.log(xhr);
        }
    });
}

I have the same question (0)
  • Suggested answer
    MikeC282 Profile Picture
    2,175 on at

    Hey bud,

    Could you not just force a save on the record before running the REST API to check for file name and extension? That way it'll exist?

  • Zohaib Uddin Khan Profile Picture
    2,822 on at

     MikeC282 - Thanks for the reply mate.

    Do you mind explaining it further? If I understand you correctly you mean:

    1. OnChange of File I'll do force save.
    2. OnSave event I'll execute the code I've written to check the file name and extension.

    With above steps it wouldn't guarantee the needed information doesn't exist in the database by the time. Please let me know your thoughts! 

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hello,

    You can write plugin on Post Create/Update to do the same validation and throw an error when validation failed.

  • Zohaib Uddin Khan Profile Picture
    2,822 on at

    Thanks Bipin for the workaround. Because of some unforeseen challenges we're not allowed to create any plugin or custom workflow. Having said that I appreciate your reply.

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hello,

    You can try below code to get the file Name using client api  on onSave event-

    formContext.getAttribute("cr127_filecolumn").fileName;

    CR108.PNG

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 Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans