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 :
Dynamics 365 Community / Forums / Field Service forum / Upload a document to S...
Field Service forum

Upload a document to Sharepoint using Rest and Javascript

(0) ShareShare
ReportReport
Posted on by 100

Hi!

I have a requirement to uploads documents from CRM to SP.

I have create the webresources, etc in the UI and I am facing the js code and honestly i am lost.

I am new in CRM and I am surfing the web looking for examples... I have found this... 

https://docs.microsoft.com/es-es/sharepoint/dev/sp-add-ins/upload-a-file-by-using-the-rest-api-and-jquery

I am playing with the first example... but I do not know even how the authrization works... and if this example is what I need

Any help would be really appreciated

Categories:
I have the same question (0)
  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    You might want to have a look on this page on how to use the standard SP integration with CRM:

    docs.microsoft.com/.../set-up-dynamics-365-online-to-use-sharepoint-online

  • faramendi Profile Picture
    100 on at

    thanks for your reply, but our requirements are not covered with the OOB integration.

    that is the reason to develop a custom solution.

    our 2 products are on-premises... to be able to connect with js and rest api, do I need to authenticate using oauth or something similar?

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    For this requirement you might need to overcome the cross-domain call issue:

    community.dynamics.com/.../crm2011-and-cross-domain-calls-part-1

    Further you can find resources on how to call SharePoint REST from a client:

    www.whypad.com/.../1169

    www.slideshare.net/.../sharepoint-2013-rest-api-remote-authentication-50591735

    this might only work for anonymous access for SharePoint.

    You might also consider to create a proxy web service that does the proper handling of authentication.

    My experiences were that JavaScript in CRM to access SharePoint outside will not work.

    Another way would be a custom action that will use a workflow activity to authenticate against SharePoint:

    code.msdn.microsoft.com/SharePoint-Integration-c5f21604

  • faramendi Profile Picture
    100 on at

    so based on your experience JavaScript is a wasting time right?

    what about the plugin? sounds good... how I would pass the file to the plugin? I should get the buffer array and set it in a hidden field of the form??

    thanks for your support

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    It depends on how you want to pass the file to CRM and SharePoint. In CRM you would usually store a file on the note entity.

    community.dynamics.com/.../240820 Mohd provided links with samples on how to work with the note(annotation) entity.

    basically its this part to get the bytes:

    string documentBody = (string)annotation.Attributes["documentbody"];

    byte[] fileContent = Convert.FromBase64String(documentBody);

  • faramendi Profile Picture
    100 on at

    We are not using notes, instead we have created a custom entity with a kendo file control, etc, etc...

    so I am not sure if is possible to set all the file array in a field to send it to the plugin... in fact I would add more information than the array of bytes... possibly formatted in xml or similar

  • Andreas Cieslik Profile Picture
    9,267 on at

    without using note attachments you will quickly have the issue regarding file sizes. Regular fields are very limited. Thats why I suggest to use notes with attachments.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Field Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans