-1

I'm new to SharePoint and I got a request to create a form with some items that get selected previously.

I did some research here and I found a topic: "Get Selected items in a list SharePoint online" which is in Javascript, but doesn't tell how to use that javascript code into SharePoint; could someone point me in the correct direction how I can accomplish this?

Vikrant
  • 4,920
  • 17
  • 48
  • 72
Paulo
  • 1
  • 1

2 Answers2

0

It was some time that I tried to communicate with SharePoint from a JavaScript frontend, but it was quite tedious.

Is the SP and FE on the same server? In my case they weren't which complicated authentication a lot. There is no "easy" way to authenticate to SP in JavaScript, as there are several validation steps, at least not at the time, so we ended up using a .NET backend. The .NET backend can use the CSOM library to authenticate and communicate with SharePoint (off and on premise). Then expose some REST API functions for the frontend to use.

I hope my experience can be of some help.

Max
  • 488
  • 8
  • 19
  • I read few posts where , people just wrap the JS code into HTML and call the HTML code from inside SharePoint Online, but I'm not familiar with the parameters that I should be adding on that wrapper, that why I post the question in here. Right now I dont have access to .NET, so for now one of my only choices is to figure out if I can use html and JS. Thanks for your comment anyway. – Paulo Oct 11 '18 at 14:54
  • If I understand right, you would use some kind of web hooks to facilitate communication between SP Online and frontend JS. I googled SP Online web hooks and found [this](https://learn.microsoft.com/en-us/sharepoint/dev/apis/webhooks/overview-sharepoint-webhooks). By skimming it through, certain events can emit POST requests. However, this option as well involves some backend that can subscribe to the POST requests. – Max Oct 12 '18 at 07:36
0

You can write a JavaScript code into an HTML, or better, you can write a separate external JS file for the same. If you are using a SharePoint 2013 Designer, you can open the site into it to modify or design the pages. In that, there is one folder viz., "Site Assets". In that, you can add a JavaScript file.

Then the JS file file reference can be given in your HTML or aspx code under the "Additional Page Head".

Pang
  • 9,564
  • 146
  • 81
  • 122
  • Thanks for your comment, I did what you suggested me but I get a blank page. what do you mean by "Additional Page Head " ? maybe that is the part that I didn't get it right. Regards. – Paulo Oct 12 '18 at 13:04
  • In a simplistic way, this is the html code that I use as my test, before I call the real JS code. ' JAVASCRIPT ' from there I called the script.js file which only have one line. ' alert('stay away'); ' – Paulo Oct 12 '18 at 13:15