Clarity Service Management

Expand all | Collapse all

create workflow via SPL Code

  • 1.  create workflow via SPL Code

     
    Posted 02-11-2018 07:40 AM

    Hi,

     

    I try create parallel workflow task via spell.

    The problem is that when I add tasks via spell to the change order all newly added tasks are with status "WAIT", instead of the first task wil get status "PENDING" and all the other status WAIT:

     

     

     

    This is my code:

    Trigger:

    OBJECT chg {
          TRIGGERS {
                POST_VALIDATE z_add_chg_wf ( ) 100 FILTER (EVENT("INSERT"));
          };
    };

     

    SPL:

    chg::z_add_chg_wf(...)

    {

     object group_leader, new_wf;

     

    //group leader

    send_wait(0, top_object(), "get_co_group");

    if (msg_error()) {

    logf(ERROR, format("Error in get_co_group: %s", msg[0]));

    return;

    }

    group_leader = msg[0];

     

    //create new first task

    send_wait( 0, top_object(), "call_attr", "wf", "get_new_dob", NULL, NULL, group_leader); 

    if (msg_error()) 

    {

    logf(ERROR, format("Error in get_new_dob: %s", msg[0]));

    return;

    }

    new_wf = msg[0];

     

    //Set the values for new work flow

    new_wf.object_type = "chg";

    new_wf.chg = id; 

    new_wf.task = "GRPSTART";

    new_wf.sequence = 10; 

     

     

    //create new task

    send_wait( 0, top_object(), "call_attr", "wf", "get_new_dob", NULL, NULL, group_leader); 

    if (msg_error()) 

    {

    logf(ERROR, format("Error in get_new_dob: %s", msg[0]));

    return;

    }

    new_wf = msg[0];

     

    //Set the values for new work flow

    new_wf.object_type = "chg";

    new_wf.chg = id; 

    new_wf.task = "WORK";

    new_wf.sequence = 20; 

     

     

    //create new task

    send_wait( 0, top_object(), "call_attr", "wf", "get_new_dob", NULL, NULL, group_leader); 

    if (msg_error()) 

    {

    logf(ERROR, format("Error in get_new_dob: %s", msg[0]));

    return;

    }

    new_wf = msg[0];

     

    //Set the values for new work flow

    new_wf.object_type = "chg";

    new_wf.chg = id; 

    new_wf.task = "WORK";

    new_wf.sequence = 30;

     

     

     

    //create new task

    send_wait( 0, top_object(), "call_attr", "wf", "get_new_dob", NULL, NULL, group_leader); 

    if (msg_error()) 

    {

    logf(ERROR, format("Error in get_new_dob: %s", msg[0]));

    return;

    }

    new_wf = msg[0];

     

    //Set the values for new work flow

    new_wf.object_type = "chg";

    new_wf.chg = id; 

    new_wf.task = "GRPEND";

    new_wf.sequence = 40;

     

     

     

    //Checkin wf object

    send_wait(0, group_leader, "checkin");

    if (msg_error()) 

    {

    logf(ERROR, format("Error checkin error '%s'", msg[0]));

    send_wait(0, group_leader, "uncheck");

    }

     

    }

    What did I do wrong in the code?



  • 2.  Re: create workflow via SPL Code

    Posted 02-11-2018 12:30 PM

    Hi,

     

    looks like there is some trigger that doesn't trigger if you insert task by spel.

    If you don't want to dive into OOTB tasks logic you can add kind of service task with autocomplete macro (on PEND behaviour) to your Change Template.

    Also you can try to insert tasks on POST_CI instead of POST_VALIDATE.

     

    Regards,

    Timur Alimov



  • 3.  Re: create workflow via SPL Code

     
    Posted 02-14-2018 09:10 AM

    Hi Timur,

     

    I tried POST_CI - same problem.

    What do you mean "you can add kind of service task with autocomplete macro (on PEND behaviour) to your Change Template"?



  • 4.  Re: create workflow via SPL Code

    Posted 02-14-2018 09:38 AM

    Hi,

     

    you can create new task type (call it Service Task for example) with Pending and Complete statuses, then attach it to your Change Template. In Change Template open newly created Service Task and go to task's behaviour and add Action Macro to Pending behaviour. Here is an example: Automatically completing workflow task 

     

    PS: group flag is an attribute of Workflow Task, so you can manually start parallel tasks without group start/group end tasks.

     

    Regards,

    Timur Alimov



  • 5.  Re: create workflow via SPL Code

    Posted 02-11-2018 05:16 PM

    Hi.

    You might want to try to do this stuff in a post_ci trigger and do a separate update/checkin of the chg object. This  might trigger the standard logic to start the workflow. Additional you might need to set the group flag for each task in the parallel group.

    Regards

    ....Michael



  • 6.  Re: create workflow via SPL Code

     
    Posted 02-14-2018 08:48 AM

    Hi Michael,

     

    What do you mean "Additional you might need to set the group flag for each task in the parallel group"?



  • 7.  Re: create workflow via SPL Code

    Posted 02-13-2018 12:16 PM

    just start your flow with an empty task and add you group start at the second may do the trick

    my 2 cents

    /J



  • 8.  Re: create workflow via SPL Code

     
    Posted 02-14-2018 09:13 AM

    Hi Jerome,

    How can I start the flow with empty task?

    Even if I start the flow with some other task I need the task to be in status completed automatiсally.



  • 9.  Re: create workflow via SPL Code

     
    Posted 02-14-2018 09:17 AM

    Hello everyone,

     

    I have tried POST_CI but it does'nt work.

    Maybe it's important what the sequence of the trigger?



  • 10.  Re: create workflow via SPL Code

    Posted 02-14-2018 09:47 AM

    As a workaround you can try to insert workflow using wf's factory method:

    add_workflow_task ( object, object, string|nil, uuid|nil, uuid|nil,
    string|nil, object|nil, uuid|nil,
    duration|nil, int|nil, date|nil, int|nil, int|nil, int|nil ) ;

    Here is an example: add_workflow_task error (solution is to define initial status as NULL)



  • 11.  Re: create workflow via SPL Code

     
    Posted 02-14-2018 12:13 PM

    Hi

    I have tried to set NULL in status and it still doesnt work. I still get status "WAIT".

    This is my new code that I tried:

    chg::z_add_chg_wf(...)

    {

    object gl, wfobj, chg, prevwf, wftpl, new1, new2;

    int i, msg_i;

     

    send_wait(0, top_object(), "call_attr", "chg", "dob_by_persid", 0, persistent_id);

    chg = msg[0];

     

    send_wait(0, top_object(), "get_co_group");

    if (msg_error()) {

    for (i=0;i<msg_length();i++) {

    logf(ERROR, "msg[%d]: %s", i, msg[i]);

    }

    }

    gl = msg[0]; 

     

    send_wait(0, top_object(), "call_attr", "wf", "add_workflow_task", 

    gl, // group leader

    chg, // parent (change, issue)

    (string) NULL, // new status

    (uuid)NULL, // asset

    (uuid)NULL, // creator

    (string)"WORK", // code

    (object)NULL, // wf template

    (uuid)NULL, // assignee

    (duration)NULL, // est_duration

    (int)NULL, // est_cost

    (date)NULL, // est_completion_date

    (int)0, // unknown int, not DB attr

    (int)0, // another unknown int, not DB attr

    (int)10 // sequence

    );

    if (msg_error()) {

    for (i=0;i<msg_length();i++) {

    logf(ERROR, "msg[%d]: %s", i, (string)msg[i]);

    }

    return;

    } else {

    for (i=0;i<msg_length();i++) {

    logf(SIGNIFICANT, "msg[%d]: %s", i, (string)msg[i]);

    }

     

    send_wait(0, gl, "checkin");

    if (msg_error()) {

    for (i=0;i<msg_length();i++) {

    logf(ERROR, "msg[%d]: %s", i, msg[i]);

    }

    send_wait(0, gl, "uncheck");

    }

    logf(SIGNIFICANT, "<< insert wf end");

    }



  • 12.  Re: create workflow via SPL Code

    Posted 02-14-2018 04:18 PM

    I used your intial code , and added  the setting of the group_task attribute to 1 for the first three tasks. Then I created a new change order with a category through the UI. Worked like a charm.



  • 13.  Re: create workflow via SPL Code

    Posted 02-14-2018 11:20 AM

    Hi Vladimir.

     

    Sorry, I pointed you in the wrong direction.

    I found the problem.

     

    You need to specify a change category. If the category is empty the start of the workflow ( chg POSTCI postci_start_process ) will just exit !

    Additionally you need to set the group_task flag to 1 for the Group Start task and all tasks within the parallel group. Otherwise only the first task inside your Group will be started.

    It will even work with your original POST_VALIDATE trigger.

     

    Please give me an idea, why are you trying to add wf tasks by your own code ?

     

    Hope that helps finally

     

    Regards

    ...........Michael



  • 14.  Re: create workflow via SPL Code

    Posted 02-15-2018 01:41 AM

    >> Please give me an idea, why are you trying to add wf tasks by your own code ?

     

    Yes, I was wondering exactly this!

     

    The "Classic" Workflow is simple by nature, with sequential operation of all Workflows, apart from those contained within a Group Start and Group End.

     

    It expects to find the "Pending" and "Wait" statements in certain places, and I'm not sure that trying to make it work in parallel via SPL inserted WF Tasks is a great idea (Disclaimer: High level, overly cautious thinking out loud from a Support person who prefers to avoid custom SPL where possible).

     

    Especially when we provide CA Process Automation along with CA SDM exactly to handle these types of situations.

     

    CA PAM has a higher learning curve initially, but it can chew through parallel or conditional processing branches and it does it very well.

     

    Thanks, Kyle_R.