How do I dynamically insert workflow GUID into URL I am building to open workflow initiation form in modal mode?

I was trying to follow the instructions in an excellent post  "Open workflow initiation form in modal dialog" but did not know how to do this step:

"I'm able to dynamically insert the GUID of the workflow as long as I know the name.  That way, if I republish the workflow, this custom action will still run correctly."

However, there was no supporting javascript example. 

It appears that step is required to make the sample code work when the workflow is republished.

Sample code *without* the workflow GUID:

    javascript:OpenPopUpPageWithTitle(L_Menu_BaseUrl + "/_layouts/IniWrkflIP.aspx?List={11449cc0-e482-4971-9ec7-f12e812f4489}&ID=" + SP.ListOperation.Selection.getSelectedItems(SP.ClientContext.get_current())[0].id + "&TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}", RefreshOnDialogClose, 600, 400, 'Assign To')

sample URL that gets built (*without* the workflow GUID):

    http://<site url>/_layouts/IniWrkflIP.aspx?List={11449cc0-e482-4971-9ec7-f12e812f4489}&ID=56&TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}

I don't know what the workflow GUID query parameter is, nor the JSOM to populate it.

Can anyone out there fill in that code gap?

*note: I am posting this as a new question because I apparently do not have permission to comment on that original post.

March 24th, 2015 6:04pm

Hi Betty,

Actually, it is not the workflow GUID that you need to achieve.

It is the workflow association ID which displays as TemplateID in the URL when starting a workflow.

To get the workflow association ID, you can get it through JSOM.

Below is a code example:

<script language="javascript" type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(GetID, 'sp.js');
var siteUrl = 'http://sp';//your site URL
function GetID(){
    var tContext = new SP.ClientContext(siteUrl);
    var tList = tContext.get_web().get_lists().getByTitle('List1');//your list name which the workflow is associated with
    this.assoc=tList.get_workflowAssociations();
    tContext.load(assoc);
    tContext.executeQueryAsync(Function.createDelegate(this, 

this.onQuerySuccess), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySuccess(sender, args){
    var wfs = assoc.getEnumerator();
    while(wfs.moveNext())
    {
        var currentWF = wfs.get_current();
        if(currentWF.get_name()=="Initiation Form")//your workflow name
        {
           var id=currentWF.get_id();
           alert(id);
         }
     }
}
 
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + 

args.get_stackTrace());
}
</script>



Best regards.

Thanks

Free Windows Admin Tool Kit Click here and download it now
March 26th, 2015 9:52pm

thank you Victoria. 

I don't think I can use code that extensive.  My 'code' is going into the "Navigate to URL" property for a custom action on my list.  Just like the example in the post I referenced.   I simply want to open the initiation form of a workflow as a modal pop-out window.  The referenced post gave the skeleton for that,

  • javascript:OpenPopUpPageWithTitle(L_Menu_BaseUrl + "/_layouts/IniWrkflIP.aspx?List={11449cc0-e482-4971-9ec7-f12e812f4489}&ID=" + SP.ListOperation.Selection.getSelectedItems(SP.ClientContext.get_current())[0].id + "&TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}", RefreshOnDialogClose, 600, 400, 'Assign To')

but since the TemplateID appears to be dynamic (changes each time you modify and republish workflow) one has to modify the "Navigate to URL" property of the custom action each time the workflow is modified and republished.

The user who posted that, 'adnauseum' left a comment that he worked around that inconvenience by using what he referred to as the workflow GUID, which could apparently serve as a constant and not need to be modified each time the workflow gets republished.  I really just wanted to see his example and how he modified the above skeleton to incorporate that, but could not comment on that post directly.  It's a couple of years old anyway, so I am not sure if 'adnauseum' could be contacted anyway or whether he could find an example of what he was talking about in his comment.

If there were some way you could respond to that comment I would appreciate it.

If not, I thank you for you fine code example and it may very well come in handy under other circumstances!

Betty

March 30th, 2015 5:54pm

Hi Betty,

The comment 'adnauseum' left is "I've found that I'm also able to dynamically insert the GUID of the workflow as long as I know the name."

In my opinion, 'adnauseum' used the workflow name to dynamically get the workflow association ID which is the TemplateID in the URL for starting the workflow.

And it did not mean the workflow GUID which is constant no matter if the workflow is republished.

The workflow GUID cannot be used the URL for starting a workflow, so you still need to get the workflow association ID which is the TemplateID in the URL dynamically with code.

Best regards.

Thanks

Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 12:49am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics