Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Creating folder in share point from D365 FO X++

(1) ShareShare
ReportReport
Posted on by 2
Hi All,
 
I have a requirement to create a new folder in the Share point whenever a new record is created on the form. I know we can achieve it through Power automate and Business events, but I cannot use that for some reason.
I have added the below code to connect to Share point using RestAPI call - I am able to authenticate the share point URL, but when I am sending the API URL as request its throwing errors as The remote server returned an error: (404) Not Found.
Error is throwing when we are getting the response. I tried with differant API URL but none of them seems to work. Can any one provide me the correct one. I will paste the code here.
Str                 apiUrl;        System.Exception    ex;        ISharePointProxy    proxy;        String255 fNewFolder = _projTable.ProjId;        String255 fServer = 'https://test.sharepoint.com/SharePointIntegrationD365FO';        String255 fRootFolder = 'Documents';        System.UriBuilder   builder     = new System.UriBuilder(fServer);        str                 hostName    = builder.Host;        str                 siteName    = fRootFolder;        str externalId = xUserInfo::getCurrentUserExternalId();        boolean validConnection = false;        proxy   = SharePointHelper::CreateProxy(hostName, '/', externalId);        if(proxy)        {            if(SharePointHelper::VerifyAuthentication(proxy))            {                validConnection = true;                info(strfmt('@ApplicationFoundation:SPServerCommunicationSuccess', hostName));            }            else            {                info(strfmt('@ApplicationFoundation:SPServerUserNotAuthorized', hostName));            }        }        else        {            info(strfmt('@ApplicationFoundation:SPSelectionDlg_ErrorNoProxy', hostName));        }        if(validConnection)        {            apiUrl = strFmt(/%1/_api/web/lists/getbytitle('%2')/folders/add('%3')/, fServer, fRootFolder, fNewFolder);            /apiUrl = strFmt(/%1/_api/web/GetFolderByServerRelativeUrl('%2')/Folders/add('%3')/,fServer, fRootFolder, fNewFolder);            /apiUrl = strFmt(/%1/_api/web/folders/add('%3')/,fServer, fNewFolder);                        try            {                str token = proxy.AccessToken;                            System.Net.WebHeaderCollection  httpHeader  = new System.Net.WebHeaderCollection();                httpHeader.Add(/Authorization/, 'Bearer ' + token);                HttpWebRequest                  request     = System.Net.WebRequest::Create(apiUrl);                request.set_Headers(httpHeader);                request.set_ContentLength(0);                request.set_Method(/POST/);                request.set_ContentType(/application/json;odata=verbose/);                System.Net.HttpWebResponse  response        = request.GetResponse();                int                         statusCode      = response.get_StatusCode();                info(strFmt(/HTTP status code: %1/, statusCode));                            }            catch            {                //exception                ex = CLRInterop::getLastException().GetBaseException();                error(ex.get_Message());            }        }
Thanks.
 
  • Layan Jwei Profile Picture
    Layan Jwei 7,266 Super User 2024 Season 2 on at
    Creating folder in share point from D365 FO X++
    Hi Mithra,
     
    Can you please re-share your code in the comments section as it's not well formatted. in order to help more.

    And In general I found this link that might help you
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans