Skip to main content
:?:

We have a main process that "kicks off" several sub processes. My question is, how can we get the name of the logged on user associated with this process? At the mo the process is showing as started by the K2 manager account and not the actual users account. Is this the usual way?

TIA,
Paul
Hi,

One way of doing this is to make sure the site is configured to run under Windows Authentication, open a connection to K2.net Server making use of K2ROM

Code:
Dim oK2Connection As New K2ROM.Connection

oK2Connection.Open(k2Server)
response.write(oK2Connection.User)


The User Property of the Connection object will return the current logged on users name DomainUserName

-------------------------------------------

If you want to see who is logged on to the current K2 ASP.Net page (site runs under Windows Authentication) you can also use:

Page.User.Identity.Name

This code will return the current logged on user's DomainUsername

---------------------------------------------

See Also Help File
User Members | SourceCode.KO Namespace

User ClassExpose all the destination user specific information.

For a list of all members of this type, see User members.

Object Model

Inheritance Hierarchy

System.Object
SourceCode.KO.User

Syntax
[Visual Basic]Public Class User
[C#]public class User
[JScript]public class User

Example
[Visual Basic]


Sub Main(ByVal K2 As ActivityInstanceDestinations)
Dim myK2ActInstDestination As ActivityInstanceDestination
Dim myK2User As User
Dim ManagedUsers As UserList
Dim UserName, UserEmail, UserManager, UserDescription As String

If Not K2.Count = 0 Then
myK2ActInstDestination = K2.Item(0)
'Get User object
myK2User = myK2ActInstDestination.User
If myK2User.Name = "Bob" Then
'Get Description
UserDescription = myK2User.Description
'Get Email
UserEmail = myK2User.Email
'Get UserList object
ManagedUsers = myK2User.ManagedUsers
'Get Manager
UserManager = myK2User.Manager
'Get Name
UserName = myK2User.Name
End If
End If
End Sub

'OR

Sub Main(Byval K2 as ServerEventContext)
SMTPFunction(K2)
End sub
Function SMTPFunction(Byval K2 as ServerEventContext)
Dim objMsg As New System.Web.Mail.MailMessage()
Dim objAttachment As System.Web.Mail.MailAttachment
Dim objSender As System.Web.Mail.SmtpMail
Dim strFrom as String
Dim strEmail As String
Dim strSubject As String
Dim strBody As String
Dim oXMLDoc As New System.Xml.XMLDocument()
Dim oNode As System.Xml.XMLNode
objSender.SmtpServer = SourceCode.K2Utilities.GeneralMod.GetDefaultSMTPServer()
strFrom = "K2Server"
strEmail = K2.ActivityInstanceDestination.User.Email
strSubject = K2.ProcessInstance.DataFields("EMailSubject").Value
strBody = "Hi " & K2.ActivityInstanceDestination.User.Name & "" & System.Environment.NewLine & "" & System.Environment.NewLine & "Your leave from " & K2.ProcessInstance.DataFields("FirstLeaveDay").Value & " to " & K2.ProcessInstance.DataFields("LastLeaveDay").Value & " has been " & K2.ActivityInstanceDestination.DataFields("ApprovalStatus").Value & "" & System.Environment.NewLine & "" & System.Environment.NewLine & "Kind Regards" & System.Environment.NewLine & "HR Department"
objMsg.From = strFrom
objMsg.To = strEmail
objMsg.Subject = strSubject
objMsg.Body = strBody
objSender.Send(objMsg)
End Function

😉

Top man, cheers David, I'll give it a try....
:?: These all seem to display the user that started the sub process, the k2 manager account, I need the user that is logged onto the Sharepoint site that will be completing the form, where can I get this username from? All the code is in a server event at the mo.

Cheers,
Paulbean
I am assuming that the parent process' originator is correct (i.e. the user that filled in the form)...

Are you using the IPC event template to start off the sub-processes? In this case, there is an option to use Originator on the 'Enter Connection Information' screen of the IPC Wizard. Note, however, that this option is only available if you entered 'local' as the server name in the preceding wizard screen and selected 'Windows Authentication' on the 'enter Connection Information' wizard screen.

The 'local' server name setting means that the sub-process will be started on the same K2.net server that the parent process is running on. This means that the parent process is able to start the sub-process as the same user that started the parent process (hope this makes sense!). In the sub-process you will then be able to use 'originator' as you would in the parent process.
Just remember to then give the relevant users sufficient permissions on the child processes to be able to start them.

Another alternative is to save the originator's information into process datafields and to pass these fields over to the child processes.

Hope this helps...

Reply