Skip to main content

Hi,

I wonder if someone can help.

I have created some links and javascript function(s) to open the edit and display forms of a SharePoint list item (from a link) in diag modal windows. This windows closes successfully when you click on either the save or cancel button. To add, these forms are Nintex forms.

I have a Nintex list workflow (to start manually). The workflow Initiation form has a few text fields the user enters, hooked up to list text fields, nothing technical.

I have constructed a url, with &scource redirect and a javascript function that opens this form in Diag Modal window. However, if you click on the save or cancel button, the workflow starts, but afterwards, the redirect page opens in the same Diag Modal window, where I need for the window to close and user to be taken to the redirect page, as is -open in the browser:

Here is the link and javascript function that successfully opens the workflow Initiation form in diag modal. I believe I am missing something to get this window to close after the workflow is either started or cancelled. Again, the form is a Nintex workflow initiation form and the buttons on the form have the same actions as the edit form that successfully closes. For the start button, save and submit action. For the cancel button - cancel action.

Link code:

<a href="javascript:openStartDialog('http://myserveraddress/_layouts/15/NintexForms/InitiateWorkflow.aspx?List={07efa1be-03c5-43b1-9e50-eff8e9db9e6b}&ID=361&ItemGuid={40EE6757-AF47-41CF-BB7B-20377D4DDE7F}&TemplateID={0411c35c-bd53-49a9-a49b-a4fb504fa8e9}&Source=http://mysiteaddress/sitepages/TCMA%20Tasks.aspx')">Some Link Text</a> 

Javascript function:

<script type="text/javascript">

function openStartDialog( sUrl ) { 

    SP.UI.ModalDialog.showModalDialog(  

      { 

        url: sUrl,

        width: 750, 

        height: 567, 

        title: "Start Task" 

     

     } 

    ); 

  } 

</script>

Can anyone help with this?


Hi,

have you tried using a dialogReturnValueCallback parameter?

I've found an interesting thread on stack overflow that could help you out:

http://stackoverflow.com/questions/8426773/how-to-refresh-a-parent-page-after-closing-sharepoint-dialog


Hi Giacomo,

I have tried amending the code but I don't think I have this right at all.

I need to close the diag modal window when either the Submit or Cancel button on the Nintex workflow Initiation form is selected.

function openStartDialog( pUrl ) {

var options = {

url: pUrl,

       width: 750, 

       height: 567, 

       title: "Start Capita Task",

dialogReturnValueCallback: ClosePopUp

};

SP.UI.ModalDialog.showModalDialog(options);

}

function ClosePopUp(result, returnValue)

{

if (result==SP.UI.DialogResult.OK)

{

SP.UI.ModalDialog.commonModalDialogClose(1,1);

}elseif

(result==SP.UI.DialogResult.Cancel)

alert ("Test");

{

SP.UI.ModalDialog.commonModalDialogClose(1,1);

}

}


Hi Darren,

sorry, I've maybe a little misunderstood your request and I've not thought about the workflow start page, so the suggestion I've given you doesn't work (it doesn't get the value from the start/cancel button so it doesn't use the dialogReturnValueCallback and it's not capable to close the dialog..

Unfortunately I'm not so high-skilled in javascript to solve this (if it has a js solution) or to propose a different kind of solution..

Maybe someone else here on the forum could help you more.. I hope so!

Giacomo


Hi Giacomo, no problem.

I think there will need to be some call (javascript- function) behind the buttons on the start form to somehow call the parent Diag modal window to close it after posting the data to the server (start workflow) or cancelling the workflow.

Anyone out there know how to do this?


OK, so I appear to be getting somewhere,

I have set both the create task and cancel buttons to call a function that will close the Diag Modal window,

In advanced settings of each button, under client click I added the following:

NWF$(document).ready(function()

{

SP.UI.ModalDialog.commonModalDialog(1,1);

}

);

This works a treat for the cancel button, but for the create task button that is a 'Save and Submit' button, it causes the window to close before starting the workflow.

I need some script/extra code to check that the workflow has started/posted the data, then call the code/function that closes the window (as above).


Hi Darren,

Are the field values on the initiation form entered by the user or do they match list item values? Depending on your requirements here I may have an alternative approach that could be a bit simpler.

Jan


Hi Jan,

the user enters some values. However,  if need be I can pul the Values from a list. What solution do you have in mind?


Hopefully I've understood the problem correctly but if not please let me know!

If you can pass in the start variables without using the workflow start form then you can just kick off the workflow directly using script and pass in the start variables in the association data, so you can potentially remove the need for a modal dialog.

I've pasted some code below that will do the basics, the association data passes in the name(s) of the variables on the workflow start form so in my example I've got one workflow variable called startVariableText and I'm passing a value of "hello world".

function StartMe()
{
   var associationData = encodeData("<Data><startVariableText>hello world</startVariableText></Data>");
   startworkflowonlistitem("your workflow name", your list item id, "your list name", associationData);
}

function encodeData(input)
{
   return input.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;");
}

function startworkflowonlistitem(wfName, itemId, listName , associationData)
{
 
    var webMethod =  _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/NintexWorkflow/Workflow.asmx';
    var soap= "<?xml version=""1.0"" encoding=""utf-8""?>" +
                            "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=""http://www.w3.org/2001/XMLSchema" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/">" +
                              "<soap:Body>" +
                                "<StartWorkflowOnListItem xmlns=""http://nintex.com">" +
                                  "<itemId>" + itemId + "</itemId>" +
                                  "<listName>" + listName + "</listName>" +
                                  "<workflowName>" + wfName + "</workflowName>" +
                                  "<associationData>" + associationData + "</associationData>" +
                                "</StartWorkflowOnListItem>" +
                              "</soap:Body>" +
                            "</soap:Envelope>";   
NWF$.ajax({
        type: "POST",
        url: webMethod,
        beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction", "http://nintex.com/StartWorkflowOnListItem");},
        data: soap,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        success: function(data) {alert("The workflow has been started");},
        error: function (e) { alert('The workflow has failed to start'); }    });
}

Hope that helps but let me know if you're still stuck.

Jan


Reply