Get Current Item Id and refresh on callback issues

Good Afternoon,

When using Forms Designer we have a lot of areas where we wish to capture data from one form and set into SessionStore to pass through to another form, either opened in dialogue or redirected. I am trying to recreate this ability within Plumsail Forms and can’t see how to get the Current Item Id to store in the session store: -

An example of the code used in Forms Designer is below
sessionStorage.clear();
var companyNameId = GetUrlKeyValue(‘ID’);
sessionStorage.setItem(‘companyNameId’, companyNameId);
var companyName = fd.field(‘Title’).value();
sessionStorage.setItem(‘companyName’, companyName); openDialogBox(_spPageContextInfo.webAbsoluteUrl +’/Lists/Contacts/fd_Item_NewForm.aspx?’);

I have tried to recreate this in Plumsail Forms but cannot, my code is below
sessionStorage.clear();
var companyNameId = window.top.fd.itemId;
sessionStorage.setItem(‘companyNameId’, companyNameId);
openDialogBox(_spPageContextInfo.webAbsoluteUrl
+’/SitePages/PlumsailForms/Contacts/Item/NewForm.aspx?’);

This doesn’t work, if I replace “window.top.fd.itemId” with say “870” a valid Item Id this works fine…

Secondly the rest of the code that goes with this is the openDialogBox function, on forms designer this code opens the New Item Form in a dialogue, and on save it then uses the call back to refresh the page. Again this does not seem to work. Help appreciated.
function openDialogBox(Url) {
var ModalDialogOptions = {
url:Url,
width:1000,
height:800,
showClose: true,
allowMaximize: true,
dialogReturnValueCallback: function(dialogResult) {
if (dialogResult != SP.UI.DialogResult.cancel) {
SP.UI.ModalDialog.RefreshPage(dialogResult)
}
}
};
SP.SOD.execute(‘sp.ui.dialog.js’, ‘SP.UI.ModalDialog.showModalDialog’, ModalDialogOptions);
};

Thanks

Dear Tony,

I’m terribly sorry for a late reply.

Please try to use this code instead:

    fd.spRendered(function() {
        sessionStorage.clear();
        var companyNameId = fd.itemId;
        sessionStorage.setItem(‘companyNameId’, companyNameId);
        var companyName = fd.field(‘Title’).value;
        sessionStorage.setItem(‘companyName’, companyName); 
        openDialogBox(_spPageContextInfo.webAbsoluteUrl
    +’/SitePages/PlumsailForms/Contacts/Item/NewForm.aspx?’);

       function openDialogBox(Url) {
           var ModalDialogOptions = {
               url:Url,
               width:1000,
               height:800,
               showClose: true,
               allowMaximize: true,
               dialogReturnValueCallback: function(dialogResult) {
                   if (dialogResult != SP.UI.DialogResult.cancel) {
                       window.location.reload();
                   }
               }
           };
           SP.SOD.execute(‘sp.ui.dialog.js’, ‘SP.UI.ModalDialog.showModalDialog’, ModalDialogOptions);
       };
    })

Dear @Tony_Duke,

Also, anyone else reading the topic. We’ve added a Dialog API to SP forms. Now you can open another form in a dialog right from JS-editor like so: Dialog.open();

Please, check out our new documentation on how to open Plumsail Forms in Dialog mode, we hope you’ll find it useful - https://plumsail.com/docs/forms/javascript/dialog.html
Also, a blog article: https://medium.com/plumsail/forms-dialogs-d8df26f9984b

The solution through native Sharepoint API is deprecated in the new version. We’ve removed unnecessary dependencies to improve performance.

Tell us if you find anything unclear, or if you have any questions!

1 Like