SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Set an infopath dropdown list on workflow form load.

Last post 05-12-2008, 4:44 PM by Cimares. 7 replies.
Sort Posts: Previous Next
  •  04-23-2008, 2:25 PM 10129

    Set an infopath dropdown list on workflow form load.

    I'm in the process of adding a status field to one of my workflow forms. It's a simple, "Yes/No/Not Applicable" choice field with only 1 of 3 values available.

    I can access this data quite happily from the workflow and pump the value back into the form using the ItemMetaData file, The problem I have is how do I tell InfoPath to set the value from ItemMetaData as the current selected item? There isn't the usual option of directing the contents of the field to a secondary data source.

    Am I going to have to create a code behind file on the form and if so, does that change the deployment method for my form?

    Cheers

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  04-24-2008, 10:55 AM 10165 in reply to 10129

    Re: Set an infopath dropdown list on workflow form load.

    Hi Paul,

    In my experience the only way to do this is using VBA code behind the infopath form. If you go to tools > programming > Microsoft Visual Studio for Applications this will open the code behind. The code in the FormEvents_Loading method should look something like the following:

    // create xpath navigator for the form controls
    XPathNavigator myNav = this.MainDataSource.CreateNavigator();
    // create xpath navigator for the external data source (from ItemMetaData file)
    XPathNavigator externalData = this.DataSources[1].CreateNavigator();
    // assign the value which needs to be selected in the drop down list
    string myValue = externalData.SelectSingleNode("/z:row/@ows_selectedVal", this.NamespaceManager).ToString();
    // set this value in the drop down list (ddlName)
    myNav.SelectSingleNode("//my:ddlName", this.NamespaceManager).SetValue(myValue);

    Once you've added your code, you will need to build this project and find out where the dll is generated (right click on the project, select Properties - Build - Output path). Then when you deploy your workflow in the normal way, copy the infopath form dll to the workflow feature folder in the 12 hive where it's xsn file lives (you could add this copying task to the install.bat file).

    Hope this helps.

    Jonathan.

  •  04-24-2008, 1:38 PM 10176 in reply to 10165

    Re: Set an infopath dropdown list on workflow form load.

    My XSNs I've been deploying with code behind have all been done through the central administration site. This has the added pain of resetting all the application pools when you add a new one.

    I just use the publish wizard as normal which packages the DLL into the XSN file.

  •  04-28-2008, 1:08 PM 10269 in reply to 10176

    Re: Set an infopath dropdown list on workflow form load.

    Thanks for the replies, as i thought, I'll have to start digging into InfoPath code behind.. something I'd been trying to avoid!!

    As I'm deploying workflows through features, I'll have to include the dll in the build script, so Central Admin is out.. but then again, if I'm installing a feature there's an IIS reset due anyhow!

    Cheers

    Paul.

     


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  04-28-2008, 1:28 PM 10274 in reply to 10269

    Re: Set an infopath dropdown list on workflow form load.

    Always read your posts with interest Paul so keen to see how you get on.

    I've done a lot of InfoPath forms now with codebehind and it's actually pretty powerful in a lot of ways. All my deployments have been done using the package and deploy inbuilt though, which as far as I can see is just creating a very specialised sharepoint solution package.

    One of the big annoyances with that is it does immediate deployment when managed though central admin so not great for rolling out new forms on a live system when it's constantly bouncing IIS!

  •  05-09-2008, 2:50 PM 10605 in reply to 10274

    Re: Set an infopath dropdown list on workflow form load.

    Ok, I've developed the first form using the code suggested. Basically, I'm pulling @ows_currentStatus out of the ItemMetadata and setting the value of the dropdown accordingly.

    The project builds ok on my laptop where I do the form design and I then use the publish feature to save the XSN file onto my dev system within the VS2005 project directory that references the task edit form.

    I now copy the .dll created by InfoPath into the same directory on the VS2005 machine during the build process.

    Once the workflow is deployed and running, I can access the edit form without any problems, however my drop down values aren't being set. What would be the best approach to try and debug the infoPath dll? Can I do it within VS2005 on the dev box or would I have to remotely attach the VSTA software on my laptop?

    (On a side note, how does the XSN no to look in it's current location for the DLL and not where it was saved on the build machine? Is it just a default path to look in the current container?)

    Cheers

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  05-09-2008, 4:35 PM 10614 in reply to 10605

    Re: Set an infopath dropdown list on workflow form load.

    Ok, I've run the code in preview mode on my laptop and it happily steps through the xPathNavigator and if I inject the string to simulate reading it from the ItemMetadata it works just fine.

    I know the metadata is being passed in as I'm also tracking it in a text block to show the value, so it seems the codebehind is not getting triggered by FormsServices. Do i need to be strong signing this and adding an entry into the web.config for it?

    Paul


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  05-12-2008, 4:44 PM 10659 in reply to 10614

    Re: Set an infopath dropdown list on workflow form load.

    Just realised, if I use the preview option from design view, my code doesn't trigger. If I open VSTO and click the debug icon it does. Any reason why this is? Have I missed an option?
    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems