This is a bit annoying (but see breaking news at the end):

You can create a function that will be called when you leave a notification, it says quite specifically in the manual that if you do this it will be called twice; once in RESPONSE mode and once in RUN mode. This is for collating votes and all that kind of interesting stuff.

To make it go you return the variable resultout with a string of the form ‘CONTINUE:YES’, where YES is the response the user made to the notification. Now, if you know your notification ID (NID) you can get the user’s response by doing something like:

Select text_value
Into response
From wf_notification_attributes na
Where na.notification_id = wf_engine.context_nid
And na.Name = ‘RESULT’;

When called in respond mode the context_nid variable is populated; when in run mode it isn’t. If you don’t return something that looks right from run mode the notification just hangs there. If you were to return a different response to what the user actually did then it would follow that path instead – good eh?

In my case I was trying to get values that were set in the notification (respond parameters in the parlance of the tool). How do you get these values if you don’t know the NID? It won’t push out of the notification and into global parameters in the workflow so you have to write a function. No use there, then. Instead I did this with a global variable. This works as long as you realise the whole thing is one Oracle transaction and the function doing your calculations is called in the order RESPONSE and RUN.

g_response wf_notification_attributes.text_value%Type := ‘’;
Function getresponse
Return Varchar2
Is
Begin
   if wf_engine.context_nid is null then
     return g_response ;
   end if ;
   Select text_value
   Into g_response
   From wf_notification_attributes na
   Where na.notification_id = wf_engine.context_nid
   And na.Name = ’RESULT’;
   Return g_response;
   Exception
    When Others Then
       Return Null;
End getresponse;

And there’s another thing: Why do I have to look in the wf_notification_attributes for a value of an attribute? Why isn’t there an API? I think there may be a Java one but honestly, everything else is in an API for the best of reasons (encapsulation and preventing a mess when you upgrade etc.). Witless.

Another way round this may be call a function after your notification; but then you’d have to get the highest-numbered NID for the notification of interest and make sure it wasn’t cancelled. Far better to be called in Respond mode. Another example of half an implementation. If they’d had respond and run mode functions definable then no issue.

Breaking news:

It just occurred to me, why not set the resultout to null when called in the mode I don’t care about?  It works! Muppets all round, I think, and I’m buying!