why is current.sysapproval.sys_class_name empty for an approval request to a catalog request?

ctu1
Giga Expert

Hi,

I have a funny situation, I put in this catalog request and find it generated an event approval.requested that is actaully meant for change task approvals. Looking at the approval events business rule, there should be a different event fired, however that doesnt happen. Then dug into this and somehow the sys_class_name just returns empty...

HELP! Paging for Mark.... 😉

8 REPLIES 8

Mark Stanger
Giga Sage

If you're going to ask for me specifically then you'll have to be satisfied with the lame answer I come up with :).

It almost sounds like the code in your instance has been modified. There is no 'approval.requested' event on demo. If you look at the code in the 'Approval Events' business rule on demo you'll see that the section of code that triggers those events looks like this...



if (current.state.changes() && current.state=='requested') {
var event = "approval.inserted";
if (isRequest)
event = "request.approval.inserted";
else if (isSCTask)
event = "sc_task.approval.inserted";

gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
updateTask(current, current.approver.getDisplayValue() + " requested to approve task");
}


Based on this, you should trigger an event of 'sc_task.approval.inserted' for a catalog task, and anything other than a catalog task or request would trigger 'approval.inserted', not 'approval.requested'.
In my testing on demo, I always get a sys_class_name of 'sc_task' and the 'sc_task.approval.inserted' event gets triggered. Try and see if you can reproduce the issue on demo. I'm guessing that your 'Approval Events' business rule is messed up.


Hi Mark,

I compared the two and the rule on demo is identical to our rule. I just messed up the event names, it is approval.inserted for us too ... sorry. However, in our testing we got an empty value for the sys_class_name. Maybe I am getting this whole thing wrong, I am just echoing what my customer found out today. He has no login yet for the forums, but I understand that will be overcome asap and he can take over. Anyways, we run approvals in a workflow on the sc_request (one approval for all items in a request). This approval action generates the event above and subsequently a notification. Any ideas?

Regards thanx, ct


The first thing I would try to do is reproduce the issue outside of the workflow. See if you get the same result by creating an approval record associated to a task. If that works, then my best guess would be that there's a timing issue where things may be happening too quickly in the workflow or they are generating a regular task rather than a catalog task in the workflow. You could try re-creating the workflow task activity and/or placing a 5 second timer delay right before the approval activity to make sure the task exists.


This is causing some real problems now. I could verify that the business rule is unmodified. I have also tried reproducting this by manually putting an approval into the sysapproval_approver table outside of the workflow. This produced no errors, the class name is set fine. However if I create an approval trough a workflow, somehow this is not the case. I have a gut feeling this could be a timing issue, because although the event approval.inserted gets raised, if I run a background script with the sys_id of approval record the 10 seconds later it comes back with a proper classname. Here is the code I used:



sys_id = "c45657cdb81b40004ed3cf848cdbb590";

var app = new GlideRecord('sysapproval_approver');
app.addQuery('sys_id', sys_id);
app.query();

while (app.next()) {
gs.print("Approval: " + app.sysapproval.getDisplayValue());
gs.print("Class Name: " + app.sysapproval.sys_class_name);
}


Here is the output I receive:
*** Script: Approval: REQ0010277
*** Script: Class Name: sc_request

Having put some logging in the approval events business rule (below) to see what it actually "sees" for the very same approval:


function checkRequest() {
var task = current.sysapproval.sys_class_name;
gs.log("CT1: current=" + current.getDisplayName() + " class=" + task);
return (task == 'sc_request');
}


Produces the following output in the log:
CT1: current=undefined class=

Somehow the workflow we use seems to insert an approval record and only after a while updates the reference to the object the approval is for. Does that make sense? What am I doing wrong?