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 :
Microsoft Dynamics CRM (Archived)

Microsoft online dynamic CRM 2015 custom file upload control

(0) ShareShare
ReportReport
Posted on by

Hello all,

I  want to upload file using custom control like <input type="file" id="myFile" multiple size="50">using javascript for this i have created html webresources.

my webresouce code:

<html><head>
<script type="text/javascript" src="new_jquery1.7.1.min.js"></script>
<script type="text/javascript" src="new_documentbody.js"></script>
<meta><meta><meta><meta></head><body style="word-wrap: break-word;">
<input type="file" id="fileUpload" style="width:500px;">
</body></html>

and function in new_documentbody.js that call on form save:

function filesave()
{
var x=document.getElementById('fileUpload');
alert(x.files.length);
}

errror: Cannot read property 'files' of null at filesave 

please advise me

thanks

*This post is locked for comments

I have the same question (0)
  • Bas van de Sande Profile Picture
    4,383 on at

    Hi Akram,

    Accessing the javascript DOM in CRM 2015 update 1 and higher is not supported anymore. Therefor it is possible that you get this null reference.

    Have you already tried to use jquery to get hold of the control?  

    e.g.  var x = $('#fileUpload');

    Bas

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    [quote user=""Bas"][/quote]

    Accessing the javascript DOM in CRM 2015 update 1 and higher is not supported anymore. Therefor it is possible that you get this null reference.

    What about usage of JavaScript DOM in Html Webresources that topic started works on? Is it unsupported as well?

  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi Andrii,

    Do not access the DOM

    JavaScript developers are used to interacting with Document Object Model (DOM) elements in code. You might use the window.getElementById method or the jQuery library. You are free to use these techniques in your HTML web resources, but they are not supported to access elements in Microsoft Dynamics CRM application pages or entity forms. Instead, access to entity form elements are exposed through the Xrm.Page object model. The Microsoft Dynamics CRM development team reserves the right to change how pages are composed, including the ID values for elements, so using the Xrm.Page object model protects your code from changes in how pages are implemented. For more information, see Use the Xrm.Page object mode

    This comes from https://msdn.microsoft.com/en-us/library/hh771584.aspx

    Instead of using document.getElementById()  one should use window.getElementById()

    Bas

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Correct thing - You are free to use these techniques in your HTML web resources. I wanted to point that topic starter develops webresource (so he can use any kind of dom manipulations inside his webresource). So actually comment "Accessing the javascript DOM in CRM 2015 update 1 and higher is not supported anymore" is not relevant.

    Also just FYI dom manipulations were never supported. Not only after CRM 2015 SP1.

  • Community Member Profile Picture
    on at

    Hi Bas,

    var x = $('#fileUpload');  not working.

    thanks for support

  • Bas van de Sande Profile Picture
    4,383 on at

    Hi Akram,

    did you try the window.getElementById()?  That one should work

    as for the $('#fileUpload'), you need to include jquery.js

    Bas

  • Community Member Profile Picture
    on at

    Hi bas,

    i have included both jquery.js and min.js but not working.

  • Community Member Profile Picture
    on at

    Hi bas,

    thank you for support.

    I think some properties are not supported IN CRM DOM like length and completed file upload.

    thanks to all for support

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans