1

How can I add attachment in SharePoint I am stuck on this problem hopefully can help me to proceed this problem. I will so much appreciate your help. Thank you.

This is the console on the browser

This is the sample screenshot of my custom script

2
  • Is it SharePoint hosted App or something else
    – Sunil Sahu
    Aug 21, 2018 at 7:46
  • Yes it is hosted app
    – junreyd
    Aug 21, 2018 at 7:56

2 Answers 2

2

You have used SP.RequestExecutor which is used for making cross domain calls and if so your _spPageContextInfo.webServerRelativeUrl won't work. Either you need to use query string to get the url or try using hard code url value. For getting url from query string

hostweburl =
            decodeURIComponent(
                getQueryStringParameter("SPHostUrl")
        );
appweburl =
           decodeURIComponent(
                getQueryStringParameter("SPAppWebUrl")
        );

var scriptbase = hostweburl + "/_layouts/15/";

For reference Click here

2
1

With regards to the error your encountering , I believe you want to change your call to _spPageContextInfo.webServerRelativeUrl to _spPageContextInfo.siteAbsoluteUrl

The following article provides a good breakdown on the properties available on _spPageContextInfo

https://sympmarc.com/2013/03/26/using-_sppagecontextinfo-to-determine-the-current-sharepoint-context-in-script/

1
  • Please specify the function of attachment or the problem on my code.
    – junreyd
    Aug 21, 2018 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.