InfoPath Comments History

  • 22 June 2009
  • 3 replies
  • 8 views

Badge +6

I would like to display history comments within an email event body, showcasing the history of all comments made by all users.


 


I created a smart object with properties ID(auto), Number(int) Date(date), User(string) and Comments(memo). I created a Create and GetList method accordingly.


In InfoPath I show two things, one multiline textbox for the current comment, and one repeating table for the history (accumulative) comments. I bind the GetList method to the repeating table and call the Create method on the submit of the form. This works like a charm, no problems.


 


When displaying this in the body of an email event, the text is not nicely structured below each other, i.e. I want to display it as is from the database (SO).


Each comment should be on a new line, showing the Date, User and Comments fields. I would like to do this in html formatting, because I also include


a link directly to the worklist url, thanks to maxpirate's help :-)


 


Can anyone shed some light?


3 replies

Badge +6

With alot of pointers found here, this one can be solved following these steps... (thanks for all the pointers from maxpirate and others!!!)


This will add history comments in html format, nicely formatted one after the other, each on a seperate line, as well as provide a direct link


to the task, which is an InfoPath client event. 


 


1. Create a smart object as pointed out in the initial post above...configure accordingly into InfoPath form


2. Create a process data field, example "Html comments" and others as indicated in the snippets below...


3. Within the K2 activity


    a. Add a email event, with the following body HTML text or similar (off course)...the [comments] and [link] text will be replaced at run time


       <html>
       <head></head>
       <body>
       Dear User  
       <br />
       Please attend to the following task below<br />
         Date: [xml field]
         Requestor: [xmlfield]  
         Description: [xmlfield]  
       <br />
       History Comments:
       [comments]
       <br />
       Please click on the [link] below to open and action your workflow task.
       <br /> 
       </body>
       </html> 


 


    b. View the code of the email event, make the following change...


            i. Comment out the line //this.EmailMessage.Body = K2.Configuration.Body;


            ii. Then add the code below


            // ***********************************************************************************
            // Customization - Add direct link to task, Add history comments


            string taskUrl = string.Empty;
            string linkUrl = string.Empty;
            string tempBody = string.Empty;


            taskUrl = "http://";
            taskUrl += K2.StringTable["RuntimeServiceServerName"].ToString();
            taskUrl += ":";
            taskUrl += K2.StringTable["RuntimeServicePort"].ToString();
            taskUrl += "/RuntimeServices/OpenInfoPathTask.aspx?";
            taskUrl += "K2Server=" + K2.StringTable["K2ServerName"].ToString();
            taskUrl += "&SN=" + K2.SerialNumber;
            taskUrl += "&XmlFN=" + K2.StringTable["InfoPathFormName"].ToString();
            taskUrl += "&Lib=" + K2.StringTable["SpsLibrary"].ToString();
            taskUrl += "&OpenAsWebPage=True&SPURL=" + K2.StringTable["SpsSiteUrl"].ToString();
            taskUrl += "&Single=True";


            linkUrl = "<a href="" + taskUrl + "">task link</a>" + "";


            tempBody = K2.Configuration.Body.Replace("[link]", linkUrl);


            tempBody = tempBody.Replace("[comments]", K2.ProcessInstance.DataFields["Html Comments"].Value.ToString());


            this.EmailMessage.Body = tempBody;


 


    c. Add a server event before the email event in point a with the following code...


       i. Access your SO used for storing your comment history, format it in html and store it in a process data field


        using System.Text;
        using SourceCode.Hosting.Client;
        using SourceCode.SmartObjects.Client;


        SourceCode.SmartObjects.Client.SmartObjectClientServer soServer = new SourceCode.SmartObjects.Client.SmartObjectClientServer();
        SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder soConnString = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
        SmartObject soAafComments = null;
        SmartObjectList soAafCommentsList = null;
        string commentsHTML = string.Empty;


            try
            {
                soConnString.Authenticate = true;
                soConnString.Host = K2.StringTable["K2ServerName"].ToString();
                soConnString.Integrated = true;
                soConnString.IsPrimaryLogin = true;
                soConnString.Port = Convert.ToUInt16(K2.StringTable["K2ServerPort"].ToString());


                soServer.CreateConnection();
                soServer.Connection.Open(soConnString.ToString());


                soAafComments = soServer.GetSmartObject("SOHistoryComments");
                soAafComments.MethodToExecute = "GetList";
                soAafComments.Properties["Number"].Value = K2.ProcessInstance.DataFields["Number"].Value.ToString();


                soAafCommentsList = soServer.ExecuteList(soAafComments);


                foreach (SmartObject so in soAafCommentsList.SmartObjectsList)
                {
                    commentsHTML += so.Properties["Date"].Value.ToString() + ", ";


                    commentsHTML += so.Properties["User"].Value.ToString() + ", ";


                    commentsHTML += so.Properties["Comment"].Value.ToString() + "<p/>";
                }


                K2.ProcessInstance.DataFields["Html Comments"].Value = commentsHTML;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("SO History Comments: " + ex.Message);
            }
            finally
            {
                soServer.Connection.Close();


                soServer = null;
                soConnString = null;
                soAafComments = null;
                soAafCommentsList = null;
                commentsHTML = null;
            }


 


Hope this is also usefull to someone else.

Badge +8
Good work sagrys, it would be useful if u could show the formatted output email as well
Badge +6

As requested, here is an output example from one of the process's email notifications...


This system I wrote in Ducth, so excuse the language, but i am sure the concept comes across just fine :-)


 


 


Beste Eric



Er is een nieuwe taak voor u aangemaakt voor de goedkeuring van een activiteit aanvraag met...



datum activiteit: 2009-06-24
aanvrager: Eric Hoedemaker
omschrijving: Ene toets voor de aanvraag activiteit



Historie opmerkingen:
2009-06-24, Lijnmanager (Sandra), niet als goed, probeer weereenz
2009-06-24, Aanvrager (Eric), ok, informatie wel aangepast
2009-06-24, Lijnmanager (Sandra), ok, alles bekijken en nou prima
2009-06-24, Assistent (Jan), alles goed en compleet
2009-06-24, MCO (Piet), alles goed, wel second opinion
2009-06-24, MCM (Claudia), als goed, tog second opinion



Klik op de task link om naar de taak te gaan.



Dit emailbericht is automatisch gegenereerd, een reactie op deze mail zal niet worden verwerkt.

Reply