Sriram Rajamanuri

I have workflow created using Sharepoint Designer 2K7 and I have saved the site as template... Now, when I create a new site from this template, the workflow does not start. It starts when I open the same workflow in Sharepoint desinger and just click 'finish'... Any thing missing here

I compared the three files in the child site for the workflow before (and after I click finish).. No change at all.. but the workflow starts working....

Is there any way I can simulate this 'finish' button click from code so that the workflows start working

thanks

sriram




Re: SharePoint - Design and Customization workflow in site template problem..

Sriram Rajamanuri

Well there is a very very circuitous workaround... Here is the code.. Am very sure this may not be the best way around, but with the limited WSS 3.0 SDK documentation and the help that is available on the web, this is what I could come up with -

private void ReAttachWorkflows(SPWeb objWeb)

{

string strXOML = string.Empty;

string strConfig = string.Empty;

string strRules = string.Empty;

SPList objWorkflowList = objWeb.Lists["Workflows"];

foreach (SPListItem objItem in objWorkflowList.Folders)

{

SPFolder objFolder = objItem.Folder;

//foreach (SPFile objFile in objWorkflowList.Folders[0].Folder.Files)

foreach (SPFile objFile in objFolder.Files)

{

objFile.CheckOut(false, string.Empty);

System.IO.StreamReader objReader;

objReader = new System.IO.StreamReader(objFile.OpenBinaryStream());

if (objFile.Name.EndsWith("xoml"))

{

strXOML = objReader.ReadToEnd();

objReader.Dispose();

}

if (objFile.Name.EndsWith("rules"))

{

strRules = objReader.ReadToEnd();

objReader.Dispose();

}

if (objFile.Name.EndsWith("xml"))

{

strConfig = objReader.ReadToEnd();

objReader.Dispose();

strConfig = strConfig.Replace("XomlVersion=\"V1.0\"", "XomlVersion=\"V2.0\""); //HARDCODED (ASSUMING VERSION IN SITE TEMPLATE IS 1.0)

objFile.SaveBinary(System.Text.Encoding.UTF8.GetBytes(strConfig));

}

objFile.Update();

objFile.CheckIn(string.Empty);

}

WebPartPagesWebService objWebPartPages = new WebPartPagesWebService();

objWebPartPages.Url = objWeb.Url + "/_vti_bin/WebPartPages.asmx";

objWebPartPages.PreAuthenticate = true;

objWebPartPages.Credentials = System.Net.CredentialCache.DefaultCredentials;

string strResult;

strResult = objWebPartPages.ValidateWorkflowMarkupAndCreateSupportObjects(strXOML, strRules, strConfig, "2");

//associate with list

string param1 = "Workflows/CreateListItemInCorrespondingList/CreateListItemInCorrespondingList.xoml.wfconfig.xml";

string param2 = "V2.0"; //THIS IS HARDCODED ...

strResult = objWebPartPages.AssociateWorkflowMarkup(param1, param2);

}

}






Re: SharePoint - Design and Customization workflow in site template problem..

jmgscott

This is an interesting workaround indeed. We are experiencing the same problem.

My question is, how exactly were you able to run this code against the workflow as it is created from the template I can't think of how this code would be incorporated into that process.

Thanks in advance for your assistance-

-James





Re: SharePoint - Design and Customization workflow in site template problem..

Sriram Rajamanuri

I have the site creation process done when the user clicks a 'button' in the parent site. So, I create site from template as step1 and then run this code snippet to 'fix' the workflow problem..

hope this helps..






Re: SharePoint - Design and Customization workflow in site template problem..

Rohit Saigal

Hi,

I am also facing a similar problem.

1. I saved a site as template.

2. Did "stsadm -o addtemplate" for the .stp file

3. Created a new site collection based on template available to me in Custom Tab while creating site collection.

Now none of the workflows work on the new created site, not my custom workflows(which work on other team sites) and not even the OOB workflows (eg. Approval).

I tried using the code you mention above, but it is NOT ABLE TO FIND ANY LIST BY NAME "Workflows" in the web object.

SPSite site = new SPSite(textbox1.text.trim());

SPWeb web = site.OpenWeb();

site.AllowUnsafeUpdates = true;

ReattachWorkflows(web);

Please help.

Thanks in Advance,

Rohit






Re: SharePoint - Design and Customization workflow in site template problem..

Sriram Rajamanuri

Are you able to open the Template site (or) the sites created from this template in Sharepoint Designer 2007 In SPD 2007, you should be able to clearly view the "Workflows" list.

Also note that this workaround is for workflows created in SPD 2007. SPD basically puts the workflows in a list by name 'Workflows'

Hope this helps






Re: SharePoint - Design and Customization workflow in site template problem..

Marius777

I also have the same problem.

I've ran that code, but it didn't help me. Could you suggest something

P.S. does CreateListItemInCorrespondingList in the line

string param1 = "Workflows/CreateListItemInCorrespondingList/CreateListItemInCorrespondingList.xoml.wfconfig.xml"

means the name of the workflow

Marius





Re: SharePoint - Design and Customization workflow in site template problem..

Marius777

allleluya!!! Smile

finnaly, i fixed that problem with workflows. That code above works only if workflow does not contains any conditions. If there is any condition in the workflow, we need to change not only "XomlVersion=\"V2.0\"", but also "RulesVersion=\"V2.0\"");

here is a code:

static string pavadinimas = "name of workflow to fix"; //write a name of workflow, that needs fixing here

static void ReAttachWorkflows(SPWeb objWeb)

{

string strXOML = string.Empty;

string strConfig = string.Empty;

string strRules = string.Empty;

SPList objWorkflowList = objWeb.Lists["Workflows"];

foreach (SPListItem objItem in objWorkflowList.Folders)

{

if (objItem.DisplayName == pavadinimas)

{

SPFolder objFolder = objItem.Folder;

//foreach (SPFile objFile in objWorkflowList.Folders[0].Folder.Files)

foreach (SPFile objFile in objFolder.Files)

{

objFile.CheckOut(false, string.Empty);

System.IO.StreamReader objReader;

objReader = new System.IO.StreamReader(objFile.OpenBinaryStream());

if (objFile.Name.EndsWith("xoml"))

{

strXOML = objReader.ReadToEnd();

objReader.Dispose();

}

if (objFile.Name.EndsWith("rules"))

{

strRules = objReader.ReadToEnd();

objReader.Dispose();

}

if (objFile.Name.EndsWith("xml"))

{

strConfig = objReader.ReadToEnd();

objReader.Dispose();

strConfig = strConfig.Replace("XomlVersion=\"V1.0\"", "XomlVersion=\"V2.0\""); //HARDCODED (ASSUMING VERSION IN SITE TEMPLATE IS 1.0)

int Index1 = strConfig.IndexOf("RulesVersion=");

char[] simb = { '"' };

Index1 = strConfig.IndexOfAny(simb, Index1);

Index1 += 2;

string skaicius = "";

while (strConfig[Index1] != '.')

{

skaicius += strConfig[Index1];

Index1++;

}

strConfig = strConfig.Replace("RulesVersion=\"V"+ skaicius + ".0\"", "RulesVersion=\"V2.0\"");

objFile.SaveBinary(System.Text.Encoding.UTF8.GetBytes(strConfig));

}

objFile.Update();

objFile.CheckIn(string.Empty);

}

kyle.WebPartPagesWebService objWebPartPages = new kyle.WebPartPagesWebService();

objWebPartPages.Url = objWeb.Url + "/_vti_bin/WebPartPages.asmx";

objWebPartPages.PreAuthenticate = true;

objWebPartPages.Credentials = System.Net.CredentialCache.DefaultCredentials;

string strResult;

strResult = objWebPartPages.ValidateWorkflowMarkupAndCreateSupportObjects(strXOML, strRules, strConfig, "2");

//associate with list

string param1 = "Workflows/" + pavadinimas + "/" + pavadinimas + ".xoml.wfconfig.xml";

string param2 = "V2.0"; //THIS IS HARDCODED ...

strResult = objWebPartPages.AssociateWorkflowMarkup(param1, param2);

}

}

}