Combining a SharePoint Server List Item with a K2.net™ 2003 Client Event

  • 24 February 2022
  • 0 replies
  • 8 views

Userlevel 3
Badge +8
 

Combining a SharePoint Server List Item with a K2.net™ 2003 Client Event

KB000007

DOWNLOADS
DOWNLOADS
PRODUCT
K2.net 2003
TAGS
Microsoft SharePoint
LEGACY/ARCHIVED CONTENT
This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.

 

Introduction

Sometimes you want to create a Task Item in SharePoint for a Client Event in a process. The functionality of having a Client Event with a matching SharePoint Server Task List Item is currently only available in the InfoPath wizards. This article describes how to combine a Default Client event and a SharePoint 2003 List event.

 

 

Configuring SharePoint

Configure an SPS list by adding a Hyperlink column called Task Link. This Task Link column will be used in K2 to point to the Client Event web page.

Configuring K2.net Studio

  1. Add an Activity to your process
  2. Set up a Destination Rule for the new activity
  3. Add an Integer data field on the process level called ListItemID This data field will be used to store the newly created list item identifier so that it can be removed again.
  4. Insert a Default Client event into this activity
  5. Open the Event Item property page for Default Client
  6. Uncheck Client Side Code, and click Ok on the warning message
  7. Check Internet and configure it to point to your ASP page
  8. Check SMTP Notification and configure it with a message for the user
  9. Click Generate Code and click Ok on the warning message
  10. Select Use Code
  11. Click Edit Code
  12. The client event code window will now open in the main view
  13. Download the zip file and open the SPSListFunction_VB.txt for VB.NET or SPSListFunction_CS.txt for CSharp file
  14. Insert -== A ==- at the top of the Sub Main function
try
{
   SPSListFunction(K2);
}
catch (System.Exception ex)
{
   throw new System.Exception(ex.Message);
}
 
  15. Append -== B ==- at the end of the client side code
private void SPSListFunction(ClientEventContext K2)
{

  // Set up variables
  string Temp, ErrorMessage = "";
  System.Int32 TempInt = 0;
  System.Int32 ListItemId = 0;

  //-=1=- Replace with your Client Event Page
  string strURL = "http://localhost/Samples/ClientEvent.aspx?sn={SERIALNO}";
  strURL = strURL.Replace("{SERIALNO}",K2.SerialNumber);

  //-=2=- Replace with your SPS Server
  string Server = "http://w2003:8080";
  if (! (Server.EndsWith("/"))) Server + = "/";

  //-=3=- Replace with your site name
  string Site = "sites/SPS";
  if (! (Site.EndsWith("/") && Site.Trim() != "")) Site += "/";

  //-=3.2=- Replace with your task list name
  string ListName = "Tasks";

  //-=4=- Replace with your domain.
  // This would be the domain that you specify when signing on
  // e.g. DomainUsername
  string Domain = "YourDomain";
  K2SPSList SpsList = new K2SPSList();

  // Set Url for Web Service
  SpsList.Url = Server + "_vti_bin/K2SpsList.asmx";

  // Set Credentials
  SourceCode.K2SPUtilities.SPSUtilities SpsUtils = new SourceCode.K2SPUtilities.SPSUtilities();
  SpsList.Credentials = SpsUtils.GetCredentials(Server);

  // Field Values
  object[] Field = new object[4];

  // FieldDesc used for URL Fields
  object[] FieldDesc = new object[4];
  for (int i = 0; i < = 3; i++)
  {
    Field[i] = "";
    FieldDesc[i] = "";
  }

  //-=5=- Replace these values with your values.
  //Look at the field mapping in the strXML assignment
  //You can add more fields by increasing/descreasing the
  //size of the array and adding to the
  //xml list.
  Field[0] = "Document Approval";
  Field[1] = Domain + "\" + K2.ActivityInstanceDestination.User;
  Field[2] = "This is a description for your task item";
  Field[3] = strURL;
  FieldDesc[3] = "Task Link";

  // Build the Xml
  string strXml;
  strXml = "";
  strXml += "" + Field[0].ToString() + "";
  strXml += "" + Field[1].ToString() + "";
  strXml += "" + Field[2].ToString() + "";
  strXml += "" + Field[3].ToString() + " ";
  strXml += " ";

  // Call Web Service to check out Document
  ErrorMessage = "";
  if (!(SpsList.CreateListItem(Site, ListName, strXml, ref ListItemId, ref ErrorMessage) ))
  {
  // Error Occurred in CreateListItem - Raise Error throw new
  System.Exception(ErrorMessage);
  }
  // Store the return value for the newly created ListItem
  K2.ProcessInstance.DataFields["ListItemID"].Value = ListItemId.ToString();
}
 
  16. Follow step -=1=- to -=5=- inside the SPSListFunction function
  17. Save the code, export and test the process

 
Look at the ClientEventComplete_CS.txt file for a complete listing of what the code should look like.

Further Suggestions

You could create a code module and call this shared function where ever you need to integrate a client event with a SPS task list

 


0 replies

Be the first to reply!

Reply