Clarity Service Management

How to skip request workflow task automatically 

02-01-2018 01:11 PM

Hi guys,

 

Consider this scenario:

 

I have a request category with 3 classic workflow task attached:

 

 

So to do this I've followed this steps:

 

1) Put the file upd_val.spl in the folder $NXROOT/site/mods/majic;

 

2) Recycle spel_srvr or restart the ca sdm services;

 

3) Create an action macro using this code:

 

macro::upd_val("cr_wf", 
format("cr = '%s' AND sequence IN (20, 30)", cr.persistent_id), // search over other tasks in the same parent request with seq 20, 30
1, 0, // delays
"status", "SKIP" // new status
);

 

4) Add this action macro to the status on task 10 that most be completed to skip the tasks 20 and 30;

 

 

 

Reference:

 

SPEL: Object update by cdtj

Statistics
0 Favorited
10 Views
1 Files
0 Shares
3 Downloads
Attachment(s)
zip file
upd_val.spl.zip   855B   1 version
Uploaded - 05-29-2019

Tags and Keywords

Comments

02-11-2019 07:46 AM

Hello James;

 

iam trying to do the same; but i have a concern looking forward for your help with, how to import the condition macro 'zWf100APP' appreciate if you can share with me the exact steps even by screenshots.

 

thanks for your patience.

 

03-26-2018 12:19 AM

You could modify the code something along these lines:

// Updated to make this appropriate for a Req/Inc/Prb workflow task
string method; method="zWfPrev2APP";

string theCR;
theCR = this.cr;
int theSeq;theSeq = this.sequence;

//
// Look up all tasks before this one, from the cr id.
//
send_wait(0, top_object(), "call_attr", "cr_wf", "sync_fetch",
"RLIST_DYNAMIC", format("cr=%d and sequence<%d and status='APP'", theCR, theSeq), -1, 0);

 

if (msg_error())
{
   logf(ERROR, "%s: Error on sync_fetch for %s WFs: '%s'", method, theCR, msg[0]);
   return;
}
object wf_list;
int wf_count;

wf_list = msg[0];
wf_count = msg[1];
logf(TRACE, "%s - %d recs found for cr %d", method, wf_count, theCR);

// If only two tasks before this one could possibly have have status APP then you can test 'if wf_count == 2'
// But if there are other tasks before this one that might have
//  status APP, and you only want to test the two immediately prior, it will be more complicated:
//  you will have to loop through the tasks that are retrieved, sort their sequence numbers (cannot assume
//  that they will be retrieved in sequence order) and the associated status and test only the final two.

if (wf_count == 2)
{
   // Have 2 prior tasks with status APP
   set_return_data(TRUE);
}
else
{
   set_return_data(FALSE);
}
 

03-23-2018 09:45 AM

This has been extremely useful and timely, thank you!

How would I account for the two previous tasks to see if either of them are APP?

02-02-2018 06:32 AM

Well done, James.

 

Different ways to do one thing. =)

This is great! THank you for share this with us.

 

Best Regards.

02-02-2018 04:52 AM

Hi Thiago,

 

well done on working this through, and apologies for not responding to your original request.

 

I hope you don't mind if I suggest a slightly simpler approach - this may also help with other things that you do with classic workflow.  The way I'd be inclined to do this is to put a 'behavior' against the Pending status on task 200 in your template: 

For this behavior the condition macro 'zWf100APP' is coded as follows.  Use type = COND rather than COND_SITE, to avoid issues if you later update the name or status of the macro through the UI:

// Updated to make this appropriate for a Req/Inc/Prb workflow task
string method; method="zWf100APP";

string theCR;
theCR = this.cr;
//
// Look up task 100 from the cr id.
//
send_wait(0, top_object(), "call_attr", "cr_wf", "sync_fetch",
"RLIST_DYNAMIC", format("cr=%d and sequence=100 and status='APP'", theCR), -1, 0);

if (msg_error())
{
   logf(ERROR, "%s: Error on sync_fetch for %s WFs: '%s'", method, theCR, msg[0]);
   return;
}
object wf_list;
int wf_count;

wf_list = msg[0];
wf_count = msg[1];
logf(TRACE, "%s - %d recs found for cr %d", method, wf_count, theCR);
if (wf_count > 0)
{
   // Have at least one task 100 with status APP (in reality of course there can only be one)
   set_return_data(TRUE);
}
else
{
   set_return_data(FALSE);
}

The 'Action on True' Action macro 'Set WF SKIP' is coded as follows:

// Set task status SKIP
this.status="SKIP";

You can follow this in task 300 with a similar Behavior.

 

The advantages of this approach (from my perspective) include:

- fewer lines of 'spel' and simpler code

- no need to allow for record locks as the 'behavior' fires on the status transition and only has to update the current task

 

The 'behavior' mechanism is very useful for this sort of requirement.  If nothing else, this illustrates my belief that there is (nearly) always more than one way to solve any requirement in SDM :-)

 

Regards,

James

Related Entries and Links

No Related Resource entered.