Storing Destination User for later use


Badge +3
I have an approval activity which will be solved by one of many members of a destination group. I need to address the actual destination user in later activities.

I also need to dispatch the id of the approver to other systems, so i recon I need to get the AD id into a process field somehow.

Can anyone help in accomplishing this?

Can it be done without code?

I'm experimenting with something like this:
K2.ProcessInstance.XmlFields["K2InfoPathSchema/my:businessFile/my:operator"].Value = K2.ActivityInstanceDestination.User.FQN;

Good approach?

11 replies

Badge +9
Hi,

You are on the correct track, however the code sample that you gave will not work. Have a look at the following code sample

 K2.ProcessInstance.XmlFields("IP").Value = SourceCode.K2Utilities.XMLFieldMod.SetXMLValue(K2.ProcessInstance.XmlFields("IP").Value, "ar:absenceRequest/ar:contact/ar:name/ar:singleName", K2.ActivityInstanceDestination.User.FQN)


I recommend that you use this code in the Client Event.

Please let me know if this is what you need.
Badge +3
I don't really get the correlation between the selected XmlField ("IP") in your sample and the XPath selector. In my XmlFields the root is called K2InfoPathSchema. Does this correlate with "IP"?

I'm trying out this one now:

, "//my:businessFile/my:operatorName", K2.ActivityInstanceDestination.User.Name);
Badge +9
K2.ProcessInstance.XmlFields("IP").Value = SourceCode.K2Utilities.XMLFieldMod.SetXMLValue(K2.ProcessInstance.XmlFields("IP").Value, "ar:absenceRequest/ar:contact/ar:name/ar:singleName", K2.ActivityInstanceDestination.User.FQN)


IP = XML Field Name
SetXMLValue([XML Field Name],[XPath to element/attribute], [Value])

You can also make use of the Data Manipulation event in K2.net Studio to get the correct Field and Xpath. Note that the event allows one to copy one value (from Data Field or XML Field element/attribute) to another field (Data Field or XML Field element/attribute). Once you completed the wizard, open the properties of the event and go to Edit Code to copy the correct code. Further note that you can not make use of the K2.ActivityInstanceDestination.User.FQN in the wizard, replace the value selected during the wizard configuration with K2.ActivityInstanceDestination.User.FQN .

Let me know if this explanation helps!
Badge +5
Hi, I am not using the K2 task pane in the InfoPath form for the K2 process but am looking for ways to mimic the Enable Submit button on Task Pane only for Destination User . The code here appears to be one of the ways to achieve this, but what about re-using the code that comes in the task pane html? What would you rather advise? Are there are any good articles/knowledge base items on this?
Badge +2
Hi. I am having problems with the code you provided. Here is the code I am using.

.Value, "my:myFields/my:Section1/my:ChangeRequestOwner", K2.ActivityInstanceDestination.User.FQN);


When I place this code in a default client event, I am getting the name of the originator and not the user in the destination rule (I am logging in as the destination user to open it up). Also, if I place the client event before the infopath event, the process just freezes up. Can you let me know what I am doing wrong, along with what order the events need to be in. Currently, the order is "Default Server", " Infopath event", then "Client Event".

Thanks in advance.
Badge +9
Are you making use of multiple destinations users? And is one of them the Originator?

Your order of event is OK but it will also depend on what you need to get out of it. Look at the following example:

# Approval Activity (3 Destination Users)
- SQL Event (insert record in DB)
- Email originator
- Client Event (for Approval)
- Email (Originator)

Additional Information: No succeeding rule configured, this will cause the Activity to be completed as soon as the first destination completed the task.

Result:
- SQL Event: this event will execute 3 times (once for each destination) resulting in 3 identical records being inserted into the DB
- Email Originator: the originator will receive 3 identical emails
- Client Event (InfoPath): create a work item for each user specified in the destination rule, once the 1st user completes the item the remaining 2 will be expired. Only the completed Activity instance will execute the remaining events
- Email: the originator will receive 1 email notification

Looking at the execution of this scenario you will find that K2.net Server creates an Activity instance for each destination user (SourceCode.KO.ActivityInstanceDestination) the only thing making each instance unique is the ID and User property, resulting in a unique serial number for each user. The succeeding rule determines the number of users that needs to complete the task before the process can continue.

Let me know if this useful.
Badge +2
Thanks for your quick reply, RĂ©nier.

I noticed that I had some left over code in the server event that set the name to the originator. It seems that my only problem is that the default client event is not getting executed. The code for my client event is as simple as this


.Value, "my:myFields/my:Section1/my:ChangeRequestOwner", K2.ActivityInstanceDestination.User.FQN);
}


There are no succeding rules and only 1 destination user. When view the flow of the instance, all events above the client event are green and the client event is white. It seems as though it is waiting on something else to finish, but when I remove the client event from the process, the workflow proceeds fine. I checked the error log and there is nothing there and the process instance has an active status. Any ideas of what the problem is?

Again, thanks in advance for your help.
Badge +9
Is that the only code in the client event? If so it explains why it is stuck, please right click on the client event and select Run Template complete the wizard, once the wizard is completed open the properties of the event, select the Use Code option and click on Edit Code . Make sure that you do not remove any existing code, add the line of code that you need to get the user name. Save and export the process before testing.
Badge +2
You are talking about the "Default Client" in the event templates window, right? When I drag one into an activity, no wizard is launched. When I right click on it and select run template, nothing happens. I just assumed that since it was a default event, it did not have a wizard tied to it, in the same way that a default activity doesn't have a wizard tied to it.

Is there something wrong with my install of k2 studio? I am using the vpc provided by the training material.

Thanks.
Badge +9
Your assumption is 100% correct, the default client event does not have a Wizard. Looking at your code I assume that you are working with a InfoPath process so the client event will then be a InfoPath client event, each client event must make use of the K2.AddWorklist method otherwise the event will be stuck without a Worklist item. In an InfoPath process you use the IP documents as the UI and for that reason will a normal client event not help you unless you create a SmartForm (aspx page). The code sample that we are working with can be added to an IP client event. If you need to use a default client event make sure that you create a form that can be used to complete the event, specifying the Internet url will result in the correct code being generated, once that s done append the code to extract the Destination user.

Let me know if you have more questions regarding this.
Badge +2
Many thanks for your prompt and informative responses.

I ended up doing exactly as you suggested and added the code to the infopath client event. I was hoping to break out the code into a different event so that I could use the nice little UI that k2 has for the infopath client event item piece, but its not really a big deal. I should be able to switch back and forth between using the GUI and using code without much hastle anyway.

Thanks again.

Reply