Obtain URL of InfoPath form in forms library?

  • 15 April 2008
  • 6 replies
  • 7 views

Badge +5

I have a process which starts with an InfoPath form from a forms library on SharePoint. When the form is submitted it goes to an InfoPath client event for approval, which by its standard behaviour puts a form into the library which can be opened to approve the item. I want to hide this library and instead have the user open the form by clicking a URL that they receive in an e-mail. What I am wondering is how I can get the URL for this form that is created by the client event, so that I can include it in the e-mail body?


Thanks


6 replies

Badge +7

If you look at the code behind the client event activity and look at the destination users section of the code you can see how the K2 wizard constructs the filename that is used to store each form in the SharePoint library. Looking at an example I put together to demonstrate breakpoints in Visual Studio 2005: http://blog.mgallen.com/?p=153 you can see how it is possible to view the code behind the wizards.


The default behaviour for the infopath form filename is something like "<Activity Name> - <Destination User> - <Serial Number>.xml"


You can capture the filename in the wizard and set a custom XML field, and then concatenate your sharepoint URL onto the front of the filename to create the URL.


If you are putting a URL inside a Mail Event body, you will probably find that if you use standard HTML e.g. <a href="http://sharepoint/formslibrary/forms/my activity - DOMAINUser - 45_11">The URL</a> the K2 wizard will wrap this in a SPAN tag making it useless as a clickable link. This presents a slight issue... but if you create the 'a href' string in code and then embed it in your email body you'll find it works correctly.


Martin

Badge +5
Thanks Martin! I have modified the code to build the URL and HTML tags and then store in an XML field. That bit works brilliantly. Now the problem I have is getting that to the user in an e-mail. I can't put the e-mail event before the InfoPath event because there will be no URL, and I can't put it after it because the workflow won't move on until it has been approved. I assume I have to code something to e-mail from within the InfoPath client event?
Badge +7

Yes for this particular one its difficult as the process is paused until the activity continues.


I wrote a .net class that I included in the project references and called a function to send mail from the part of the code where the URL is generated.


// create mail message object
MailMessage mail = new MailMessage();
mail.From = "";           // put the from address here
mail.To = "";             // put to address here
mail.Subject = "";        // put subject here
mail.Body = "";           // put body of email here
SmtpMail.SmtpServer = ""; // put smtp server you will use here
// and then send the mail
SmtpMail.Send(mail);


The code above will work in the workflow code with some tweaks... you can get the smtp server from the K2 environment strings.


The email body can be a flexible as you'd like... i've seen an example of creating an email body similar to that of the default notification event.


While on that thought, could you not customise the default notification event for your purposes? This contains the URL of the infopath xml... you can get at that code too, and hack away to your hearts content ;-)


Martin

Badge +5

icon-quote.gifmgallen:
While on that thought, could you not customise the default notification event for your purposes? This contains the URL of the infopath xml... you can get at that code too, and hack away to your hearts content ;-)


Do you mean the notification option that the InfoPath client event wizard gives you? I enabled this yesterday and then was looking through the code trying to find something I could modify, but I couldn't find the function for this at all. It would be good if I could customize that.


 Thanks for the other suggestion as well.

Badge +7

Ahh yes.... I believe that this is probably handled by the message queuing... so the code is outside of the workflow... so this probably isnt worth touching.


Hopefully someone will back this up with fact rather than my assumption.


Martin

Badge +9
You are correct Martin.  Out of box workflow notifications are handled via the K2 Event Bus.  The K2 Event bus utilizies the MSMQ message queues.  As such the workflow simply generates a message and the event bus sends the email (from outside the process).

Reply