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 :
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.
 
I have the same question (0)
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 512 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 291 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans