none
SP.UI.ModalDIalog.showModalDialog from AddIn with NewForm on a hostweb collection list?

    Question

  • Hello,

    I created a SharePoint Online AddIn in which I would like to open newform.aspx of a calendar-/event-list in the hostweb in a modal dialog.
    This AddIn reads data from this list and displays it in the addin itself via JavaScript.
    Therefore I would like to use the modal dialog because then it will be possible to use a DialogReturnValueCallback - function which will refresh the "data-display-page" of the AddIn if a new calendar entry is created or modified.

    If I use SP.UI.MocalDialog.showModalDialog with a hostweb URL I will get a runtime error in JavaScript (0x80070005 access denied). If I will use it the same way with a list with the same list stored in the appweb itself it works without any problems.

    In the AppMaifest.xml I added "FullControl"-permissions to the SiteCollection.

    Does someone know if it is possible to use modal Dialog from appweb to a list stored in the hostweb or if I can use another way to Display newform.aspx or editform.aspx of a list stored in the hostweb from appweb and can use a callback-function to refresh dataview in the appweb?

    Thank you very much for your suggestions in advance!

    Kind regards,
    Robert.

    Friday, September 16, 2016 1:45 PM

Answers

All replies

  • Hi Robert,

    We can open list new item form from host web in modal dialog in add-in.

    Please add the line of code below to the list new item form page for allowing the page to be displayed in an iframe:

    <WebPartPages:AllowFraming runat="server">

    Although we can open the new item form in modal dialog in add-in, however we cannot save the item back to the list by clicking the Save button.

    So I recommend to create custom form and use REST to save the results back to lists in host web from add-in.

    http://blog.ch.atosconsulting.com/performing-rest-operations-on-host-webs-from-sharepoint-hosted-apps/

    Best Regards,

    Victoria

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, September 20, 2016 5:39 AM
    Moderator
  • Hi Victoria,

    thank you very much for the information you provided.

    I tried to add "<WebPartPages:AllowFraming runat="server"> to the newform.aspx of the list which is placed in the hostweb via SharePoint Designer but after that unfortunately I also wasn't able to open the newform.aspx in modal dialog.
    I got the same access denied error message.

    I would like to avoid creating custom forms for new items and also to display or edit existing items in the addin because it seems more complicated for me to do this and to "completely" link it with the JavaScript calendar application provided with the addin, so I thought to open the "normal" forms of the hostweb lists in modal dialog would be easier and I thougt that "save" button won't be a problem...

    So I will try to check custom forms with REST as you provided in your post.

    Thank you very much and best regards,
    Robert.

    Monday, September 26, 2016 11:13 AM
  • Hi RoMeH,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, October 3, 2016 10:00 AM
    Moderator
  • Hi Victoria,

    thank you for your request!

    In the meantime I managed it to open the original newform.aspx from hostweb in the addin.
    First I used the default.aspx site of the SharePoint Addin created from Visual Studio and that didn't work.
    If I create a Webpart site and use the "AllowFraming" option there then I'm able to open newform.aspx in modal dialog.

    But this didn't solve all the problems because you also told me that we are not able to save new or updated entries of the hostweb-list via this method, so the only way will be REST with custom forms in the app.
    Till now I unfortunately didn't have time to check this.

    If it is better I can mark this question as "solved" now otherwise I will add a comment if I was able to realize REST with custom forms as soon as I had enough time to try and realize it.

    Kind regards,
    Robert.

    Monday, October 3, 2016 11:47 AM
  • Hi Robert,

    Thank you for replying back and letting us know the progress.

    You can mark a reply as answer if you think the reply is helpful and if the solution cannot work after testing, then you can unmark the reply as answer and we will provide more assistance if you need.

    Thanks again for your understanding and support.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, October 4, 2016 1:58 AM
    Moderator
  • Hello,

    now I tried to to read- and write-operations with REST according to

    http://blog.ch.atosconsulting.com/performing-rest-operations-on-host-webs-from-sharepoint-hosted-apps/

    Read-operations are working without any problems but "POST"-operations don't work, there I will get a "403 forbidden" error even with the necessary rights set in appmanifest.xml as described in thist link.
    I also tried REST-write-operations on a simple list stored in the appweb itself but with the same error, reading-operations are also working there.

    I'm using SharePoint Online/365, so could it be that REST-"POST"-operations are working a little different then described in the link above provided by Victoria?

    In the comments at the buttom of this link I saw that other people also have 403 errors accessing external lists also with read-operations from an app. But read-operations are working in my case and I think write-operations should work in every way in a list stored in the app/appweb itself...

    Kind regards,
    Robert.

    Tuesday, October 4, 2016 2:18 PM
  • Hello,

    now I used SP.RequestExecutor and "method" instead of "type" and "body" instead of "data" and removed the "X-RequestDigest" as descripted in the following link:

    https://social.msdn.microsoft.com/Forums/office/en-US/49fa9df3-37f8-4b35-a74a-1ab67ce8ed62/sharepoint-online-rest-call-to-create-item-403-forbidden?forum=appsforsharepoint

    Now it works...

    Kind regards,
    Robert.

    • Marked as answer by RoMeH Tuesday, October 4, 2016 6:00 PM
    Tuesday, October 4, 2016 6:00 PM