Skip to main content
aahh, yes.

That would be a nice work around to maintain the system as dynamic as possible in stead of hard coding everything in the escalation (which is also not really possible due to not having the serial). Guess you could store the serial as activity data field, but that COULD escalate the problem expotential.

I like your way of thinking (problem solving), and are most greatful for all the assistance. Thank you!
Hi,

I've build a mailer in the code module. As a result all my mails are generated via this function. Mainly this function is used via the ClientEvents (Var assigned as ClientEventContext).

I can not however use this function via the serverEvents (Var assigned as ServerEventContext) or via Escalation Rules (Var assigned as EscalationRuleContext). Is there a way how I can use this mailer via either server events or escalation rules as well?

Thanks.
Morne
I assume you're passing the ClientEventContext into the code module so that you can access a property or method on the ClientEventContext?

How about modifying the code module so that the method accepts an object as the parameter - you can then check the type at runtime and do a implicit conversion for the object so that you can get to the method/property again.

NOTE: check for the type prior to trying the implicit cast to avoid an invalidCastException, and make sure that the property/method you;re calling on the eventContext actually exists.

a very simplified example:


public class someClass
{
public string getSerialNumber(object eventContext)
{
string serialNumber = "";
if (eventContext is ClientEventContext)
{
serialNumber = (ClientEventContext)eventContext.SerialNumber);
}
else if (eventContext is ServerEventContext)
{
serialNumber = (ServerEventContext)eventContext.SerialNumber);
}
return serialNumber;
}
}


hope this helps. there are other ways of achieving this as well (you can modify the module to accept the values you need to use as strings, for example) but the approach used above will probably be easier to maintain.
Thanks. It seems like you are onto something that will definitely help, although i can not get it to work, or I do not understand it in the way intended for. Below my attempt to do the conversion. It gives errors on the if is clienteventcontext statement (changed all clienteventcontext types to objects now)

See, main objective is to generate all mails from 1 function (branded email which also change as the wind direction change as per client's request) and also to include the Web URL, etc. in my reminder email (done via escalation rule). But I can not get the url which is determined in the sendmail function and set for the email and the worklist item.

Below the modified clientevent function on the activity:

Sub Main(ByVal K2 As Object)
Try
'STEP: Approve Application
Dim theEmail As New Functions()
Dim OtherVar As String

OtherVar = ""
theEmail.SendEmail(K2, OtherVar)
Catch Ex As System.Exception
Throw New System.Exception(ex.Message)
End Try
End Sub


below an extraction of the mail event
 - " & K2.ProcessInstance.Process.Description & " - #" & K2.ProcessInstance.Folio

'BODY
strBody = "<font face='Arial' size='2'>" & "Hi " & K2.ActivityInstanceDestination.User.Name & ",<br>"

'ect. ect.

K2.AddWorklist("ASP",System.Web.HttpUtility.UrlPathEncode(strURL))
End Sub
End Class


PS! I'm not a C# guru (and a K2 beginner), so apologies if mine not working due to small irrelevant syntax error.
this should fix the syntax error (my VB is a bit rusty, though):

[quote user= CType(K2Temp,ClientEventContext)
'SUBJECT
Dim strSubject As String = " - " & K2.ProcessInstance.Process.Description & " - #" & K2.ProcessInstance.Folio
'BODY
Dim strBody As String = "<font face='Arial' size='2'>" & "Hi " & K2.ActivityInstanceDestination.User.Name & ",<br>"
'ect. ect.
End If
' K2.AddWorklist("ASP",System.Web.HttpUtility.UrlPathEncode(strURL))
End Sub
End Class


The K2.AddWorklist("ASP",System.Web.HttpUtility.UrlPathEncode(strURL)) line should, in my opinion, not be in the code module that sends the email since it has nothing to do with sending the email.

Also, be careful of the escalation event - if you're trying to send the URL to the new clientevent that was created because you did a send-to escalation in the escalation rule, you will not have access to the serialnumber of the client event context yet.

Hope this helps!

You are an absolute GENIUS!! It's working.

Reason for addWorklist in there is because the URL is created based on certain variables passed to the function, and more variables are added to query string which affects the display of the actual page. But you are right there as well, suppose I have to put that in a function of its own, i.e. a function for generating the URL.

Thank you so much!

You've reduced my functions for generating mail from 3 (Client-, Server-, EscalationActionContext) back to 1 again.
Oops.

See what you mean regarding SerialNumber. That is an interesting curve ball in the whole equation.

Any idea what the approach would be to get serial number from the escalation rule?
Any idea what the approach would be to get serial number from the escalation rule?

There isn't, really. The problem is that the escalation event code and the client event code are executed separately. If you're doing a 'redirect to' escalation, the escalation rule code will complete first before the client event code which creates the worklistitem is executed.

A suggestion would be not to try to send the email in the escalation event - maybe set an activity or process datafield (e.g. 'TimesEscalated') in the escalation rule and then check this datafield in the client event code - if the field's value is greater than 0 then the escalation must have fired and you can modify the notification message accordingly.

Reply