0

I am trying to get the script found under 'Enforce Drag and Drop documents to apply metadata' to work and I am always getting an 'Undefined' error here:

$.getScript("path_to_my_custom_js_file/DragDrop.Extended.js");

I have tried several different locations and ways to write the URL but it always comes back with the same error. Any help will be appreciated, thanks.

1 Answers1

0

Suppose .js file is located in a folder in _layouts folder, then use following code to load the file:

var url = _spPageContextInfo.siteAbsoluteUrl + '/_layouts/15/FolderName/DragDrop.Extended.js
$.getScript(url);

Suppose the file is located in a folder in dcoument library in root site collection named. Then this code can be used:

var url = _spPageContextInfo.siteAbsoluteUrl + '/LibraryUrl/Folder/DragDrop.Extended.js'
$.getScript(url);

UPDATE

If the library is in sub site and the page where you are running the script is also in that same subsite, then you can use:

var url = _spPageContextInfo.weAbsoluteUrl + '/LibraryUrl/Folder/DragDrop.Extended.js'
    $.getScript(url);
Nadeem Yousuf-AIS
  • 18,707
  • 4
  • 28
  • 59
  • The .js file is located in the document library. I tried your suggestion but it still gives me the undefined error. – Allan Syvret Feb 02 '15 at 14:58
  • Can you paste some code in the question. Also, is the document library in a root site collection or in a subsite? – Nadeem Yousuf-AIS Feb 02 '15 at 15:03
  • Here is the part of the code that is giving me issues, along with the start of the script: – Allan Syvret Feb 02 '15 at 15:06
  • The Document Library is in a subsite. – Allan Syvret Feb 02 '15 at 15:08
  • And where is the page that is using this script. Is it also in the subsite? – Nadeem Yousuf-AIS Feb 02 '15 at 15:11
  • Yes, it is on the same subsite. – Allan Syvret Feb 02 '15 at 15:13
  • @AllanSyvret, see my updated answer. – Nadeem Yousuf-AIS Feb 02 '15 at 15:15
  • @ NadeemYousuf, It still gives me the same error. – Allan Syvret Feb 02 '15 at 16:04
  • Use Browser developer tools to check what url is getting created and then paste that url in separate browser window to check if you can browse the file – Nadeem Yousuf-AIS Feb 02 '15 at 16:14
  • The browser can see the file correctly. I have even tried it with another script that launches correctly when launched directly from a Script Editor web part and it gives me the same error. – Allan Syvret Feb 02 '15 at 16:40
  • OK, now it does not give me the 'Undefined' error. I changed some of the security settings and it seems to have solved that problem. Now the rest of the script is not working but I'll post another question for that. @NadeemYousuf, thanks for your help the var url helped. – Allan Syvret Feb 02 '15 at 20:26