0

I want to write a workflow for SharePoint 2013 in Visual Studio. How do I know what user using (add, update or delete) an item?

And I have no columns with unique data.

1
  • The way your question is phrased, is sounds like you're looking for help writing the workflow. But you're asking how to detect from within the workflow whether an item is new or has been edited, is that correct? And just a note, workflows can't detect when an item is deleted, because a deleted item doesn't exist anymore for the workflow to do anything with it. However, and event receiver can detect deletions.
    – Erin L
    Jun 7, 2016 at 15:42

3 Answers 3

3

First, every SharePoint list has a unique column and it's titled ID or OWS_ID.

Do you need a workflow or an event handler?

Edit. Your question is real broad and there are tons of online resources geared towards creating Visual Studio SharePoint workflows. Suggest you try one of the tutorials, then come back to this site with an exact question.

MSDN - Develop SharePoint 2013 workflows using Visual Studio: https://msdn.microsoft.com/en-us/library/office/jj163199.aspx

2
  • I have SPList with thousands items. We have other solution for this problem? And I need workflow. Jun 7, 2016 at 12:57
  • you can build the workflow easily with SharePoint Designer and there you can define which user will use or action the workflow
    – Red
    Jun 7, 2016 at 13:18
1

In Visual Studio, you can get the person who started the workflow using SPWorkflowActivationProperties Originator property.

In Designer, you can use [%Workflow Context:Initator%]

1

If you need to know the current logged in user:

SPWeb theSite = SPControl.GetContextWeb(Context);
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;

(https://stackoverflow.com/questions/2423268/how-to-find-the-logged-in-user-in-sharepoint)

If you need to know who the creator (author) of an item is:

string loginName = string.Empty; 
SPWeb spWeb = SPContext.Current.Web; 
var fullUserName = spListItem[SPBuiltInFieldId.Author] as string; 
var userName = fullUserName.Split('#')[1];
SPUser spUser = spWeb.EnsureUser(userName);
loginName = spUser.LoginName;

(http://jsuhail.blogspot.com/2014/02/retrieve-author-of-splistitem-as-spuser.html)

Not the answer you're looking for? Browse other questions tagged or ask your own question.