Returning list item id

  • 23 September 2010
  • 3 replies
  • 0 views

Badge +3

I have created a simple workflow that creates a list item and sends to list item id to an email address. This works without any problems.


 I would like to change the workflow so that I can:


1.  Call the process from an aspx page,
2   Populate the list item information form the apsx page
3.  Save the list it
4.  Have the process return the list item id


I have steps 1-3 working, however, I cannot get the list item id back from the process


Here's the code I'm using:


string ListId ;
Connection conn = new Connection();
conn.Open("xxxxxx");
string name = @"ManageListItem1Request List Item";
ProcessInstance pi = conn.CreateProcessInstance(name);
pi.DataFields["Title"].Value = this.txtTitle.Text;
pi.DataFields["Message"].Value = this.txtMessage.Text;


ListId = pi.DataFields["ListItemID"].Value.ToString();
pi.Folio = this.txtTitle.Text; 
conn.StartProcessInstance(pi);
blInfo.Text = "Your item id is " + ListId;
conn.Close();


 


 


 


3 replies

Badge +7

What are you getting as your blInfo.Text? I would set a breakpoint and step through the code to see what data you're getting from the code.

Userlevel 1
Badge +8

From the code you provided, I don't think you will ever be
able to get the List Item ID back for a couple of reasons.


First, the code you provided would need to be executed in synchronous
mode. This is very helpful in scenarios where you are starting a new process
instance and need to capture the process id for some reason. To execute your
startprocessinstance as synchronous, your code would look something like this:


conn.StartProcessInstance(pi, True);


This causes the API to wait for the process instance to
start before returning control to the web application.


Second, the code I just discussed is all impacting the
process start. Your process does not create a list time until the first
activity AFTER process start, so at that point after the process successfully
starts and returns control to the web application, the activity with the list
item creation events hasn't executed at that time so there isn't an Item ID to
return.


 


 

Badge +8

If you just intend to create the List Item in the process, you could consider just using a SmartObject for this, instead of starting a process. With the SharePoint Service, you can easily create the SmartObject from the List and then just execute the Create method in your code. After executing the SmO you will be able to get the List Item ID from the ID property.

Reply