I am trying to create folder into share point list and add items into newly created folder.
Currently i am open newform.aspx page with folder path which was not already exists as below:- https://sharepointonline.com/sites/SiteName/Lists/ListName/NewForm.aspx?IsDlg=1&RootFolder=/sites/SiteName/Lists/ListName/Folder1/Folder2
When user click on save button with items details i am creating Folder1 and Folder2 using code into presave. Folders are created successfully but item is not inserted into it, it throws error that folder path not exists.
If i refresh page and try to add item, it will easily inserted into folder.
Please help me in this.
JSOM/Rest api are asynchronous,you should try to delay the add item function and return when previous function complete.
Try to use jQuery
Deferred
for this case.You may check this thread for a sample demo.