CA Service Management

Expand all | Collapse all

Prevent request status change if all workflow tasks are not completed

Grant Bruneau

Grant BruneauOct 12, 2018 02:37 PM

  • 1.  Prevent request status change if all workflow tasks are not completed

    Posted Oct 12, 2018 09:27 AM

    Hi everyone,

     

    I have a request to disable users to change the status of a request to Resolved 'RE' (not Closed) if all of request workflow tasks are not in status Complete.

     

    Anyone have maybe a solution how to accomplish this or maybe a macro code that will prevent this?

     

    Many thanks,

     

    Domagoj



  • 2.  Re: Prevent request status change if all workflow tasks are not completed

    Posted Oct 12, 2018 12:06 PM

    Hi,

     

    I have similar logic I built to stop change orders from transitioning to Implemented if all workflow tasks are not complete. I re-wrote this for request workflow and have not tested it. Please try this in a test env first.

     

    Create a file named z_cr_wf.mod and place in nx_root/site/mods/magic with the following contents.

    MODIFY cr     POST_VALIDATE zCheckPendingWF() 50012 FILTER(status { -> 'RE' } && EVENT("UPDATE"));

     

    Create a file named z_cr_wf.spl and place in nx_root/site/mods/magic with the following contents.

    cr::zCheckPendingWF(...) {
         object wf_list;
         int wf_count;
         string method, wc_workflow;
      method = "cr::zCheckPendingWF";
      logf(MILESTONE, "%s started", method);
     
      //Where clause to check to workflow tasks
      wc_workflow = format("cr = %s AND status = 'PEND')", persistent_id);
       
         uuid who;
         send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
         who=msg[0];
     
      send_wait(0, top_object(), "call_attr", "cr_wf", "sync_fetch", "STATIC", wc_workflow, -1, 0);
      wf_list = msg[0];
      wf_count = msg[1];

      //If there are pending workflow tasks then block the action
      if(wf_count > 0){
              set_error(1);
              set_return_data("Please complete all pending workflow before changing the status to Resolved.");
              return;
      }
      logf(MILESTONE, "%s ended", method);
    }

     

    Test and let me know if it works.



  • 3.  Re: Prevent request status change if all workflow tasks are not completed

    Posted Oct 18, 2018 04:59 AM

    Thanks Grant,

     

    will test and let you know if it helps.

     

    Best Regards

     

    Domagoj



  • 4.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Feb 25, 2021 09:46 AM
    Hi Grant,

    We have same requirement of restricting cr status to Resolved if the workflow tasks are Pending or Active. I have used your code but getting below errors. Please help in resolving the error:-

    02/25 20:13:54.31 SDM01 domsrvr 8844 ERROR where.y 908 Parse error at : "cr = cr:676306 AND status = 'PEND')" (Bad where clause)
    02/25 20:13:54.32 SDM01 spelsrvr 20604 ERROR pcexec.c 6554 Spell interp failed at cr::zCheckPendingWF (...) verify_wf.spl:16: Math argument type mismatch
    02/25 20:13:54.33 SDM01 spelsrvr 20604 ERROR pcexec.c 6500 Spell interp failed at verify_wf.spl:17:cr::zCheckPendingWF: Reply message [1]: bad index - size is 1
    02/25 20:13:54.34 SDM01 web:local 9932 ERROR freeaccess.spl 25902 update checkin of cr:676306 failed: verify_wf.spl:17:cr::zCheckPendingWF


  • 5.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Feb 26, 2021 01:45 AM

    The %s in the wc_workflow is missing single quotes, that's all. So line

    wc_workflow = format("cr = %s AND status = 'PEND')", persistent_id);

    becomes

    wc_workflow = format("cr = '%s' AND status = 'PEND')", persistent_id);



  • 6.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Mar 02, 2021 06:37 AM
    I am able to run the code:-
    =========================================================
    cr::zCheckPendingWF(...) {
    object wf_list;
    int wf_count;
    string method, wc_workflow;
    method = "cr::zCheckPendingWF";
    logf(MILESTONE, "%s started", method);

    //Where clause to check to workflow tasks
    wc_workflow == format("cr == '%s' && status == 'PEND')", persistent_id);

    uuid who;
    send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
    who=msg[0];

    send_wait(0, top_object(), "call_attr", "cr_wf", "sync_fetch", "STATIC", wc_workflow, -1, 0);
    wf_list = msg[0];
    wf_count = msg[1];

    //If there are pending workflow tasks then block the action
    if(wf_count > 0){
    set_error(1);
    set_return_data("Please complete all pending workflow before changing the status to Resolved.");
    return;
    }
    logf(MILESTONE, "%s ended", method);
    }
    ================================================================================================

    This code is restricting me to change to Resolved status, even if there are no workflows or all the workflows attached are Approved or Completed status. On checking logs, I am getting below error. There are only 5 workflows attached to the cr ticket. Please guide how to resolve this issue.

    Error Log----------------------------------------------------------
    03/02 16:46:08.14 UATVWSDM01 spelsrvr 8156 SIGNIFICANT zresolve_date.spl 3 status: RE, resolve_date: 03/02/2021 16:46:08
    03/02 16:46:11.05 UATVWSDM01 sqlagt:select5 6088 SIGNIFICANT prov_base.c 1010 SQL Query has returned (5000) rows for (domsrvr/superuser/ServiceDesk). Clause (SELECT crwf.id FROM crwf) Input (<None>)
    03/02 16:46:11.50 UATVWSDM01 sqlagt:select5 6088 SIGNIFICANT prov_base.c 1025 SQL Query has finished (9217) rows for (domsrvr/superuser/ServiceDesk). Clause (SELECT crwf.id FROM crwf) Input (<None>)
    03/02 16:46:11.52 UATVWSDM01 web:local 5628 ERROR freeaccess.spl 25902 update checkin of cr:679824 failed: Please complete all pending workflow before changing the status to Resolved.


  • 7.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Mar 02, 2021 07:58 AM

    Your issue is this line:

    wc_workflow == format("cr == '%s' && status == 'PEND')", persistent_id);

    It causes your search for WF tasks to run without any where-clause and returns every single task in the system. I don't know how you got the idea that modifying the where-clause that way would be OK, but fix the double-equalities and you should be golden.




  • 8.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Mar 02, 2021 02:46 PM
    As i am not well versed with spell codes, I am struggling to get the code right and working in my environment but failing. I would highly appreciate if someone can help in sorting the error:- Below is the code I am running:-
    cr::zCheckPendingWF(...) {
    object wf_list;
    int wf_count;
    string method, wc_workflow;
    method = "cr::zCheckPendingWF";
    logf(MILESTONE, "%s started", method);

    //Where clause to check to workflow tasks
    wc_workflow = format("cr = '%s' AND status = 'PEND'),persistent_id");
    uuid who;
    send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
    who=msg[0];

    send_wait(0, top_object(), "call_attr", "cr_wf", "sync_fetch","STATIC", wc_workflow, -1, 0);
    wf_list=msg[0];
    wf_count=msg[1];
    //If there are pending workflow tasks then block the action
    if(wf_count > 0){
    set_error(1);
    set_return_data("Please complete all pending workflow before changing the status to Resolved.");
    return;
    }
    logf(MILESTONE, "%s ended", method);
    }
    ===========================
    ERROR
    =================================
    03/03 01:03:40.49 UATVWSDM01 spelsrvr 10812 ERROR pcexec.c 6500 Spell interp failed at verify_wf.spl:9:cr::zCheckPendingWF: Arg mismatch in printf or scanf
    03/03 01:03:40.50 UATVWSDM01 web:local 6232 ERROR freeaccess.spl 25902 update checkin of cr:678975 failed: verify_wf.spl:9:cr::zCheckPendingWF


  • 9.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Mar 02, 2021 06:48 PM
    Hi,

    wc_workflow = format("cr = %s AND status = 'PEND')", persistent_id);​

    Did you count the brackets as well? 
    You have one opening and two closing brackets.
    I think this is the correct syntax:
    wc_workflow == format("cr='%s' && status='PEND'", persistent_id);

    Best regards
    Janos Mertz



    ------------------------------
    Senior Services Consultant
    Enterprise Studio, HCL Technologies Austria GmbH
    ------------------------------



  • 10.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Mar 03, 2021 02:17 AM

    @Janos Mertz You caught the extra closing parenthesis which I missed, but don't add the double-equals there, there will be only single equals signs on that row.

    @Sushovan Sinha SPEL syntax is pretty much like C++, but are you sure you should be touching the code? I see you struggling with very basic programming concepts and we're not even talking anything specific to SPEL. If you're stuck in a situation where you are the only one available then you've got no options, but otherwise I suggest delegating this to someone with at least some experience with any C-like language.




  • 11.  RE: Re: Prevent request status change if all workflow tasks are not completed

    Posted Mar 03, 2021 03:53 AM
    Hi Janos, Jussi,

    On removing the double equals I am getting parse error. 

    wc_workflow = format("cr='%s' && status='PEND'", persistent_id);

    Error:

    03/03 14:15:02.74 UATVWSDM01 domsrvr 14068 ERROR where.y 908 Parse error at : "cr='cr:679824' && status='PEND'" (syntax error)
    03/03 14:15:02.75 UATVWSDM01 spelsrvr 4608 ERROR pcexec.c 6554 Spell interp failed at cr::zCheckPendingWF (...) verify_wf.spl:16: Math argument type mismatch
    03/03 14:15:02.76 UATVWSDM01 spelsrvr 4608 ERROR pcexec.c 6500 Spell interp failed at verify_wf.spl:17:cr::zCheckPendingWF: Reply message [1]: bad index - size is 1
    03/03 14:15:02.77 UATVWSDM01 web:local 1052 ERROR freeaccess.spl 25902 update checkin of cr:679824 failed: verify_wf.spl:17:cr::zCheckPendingWF


  • 12.  Re: Prevent request status change if all workflow tasks are not completed

    Posted Oct 12, 2018 12:17 PM

    Hi,

    gbruneau's solution should work fine but if you want to resolve this using just Data Partition, this one constraint could help:

    NOT( id.[chg]workflow.status.task_complete = 0 ) 

    PS: conditions with "NOT" constraint could work very slow, so use it at your own risk.



  • 13.  Re: Prevent request status change if all workflow tasks are not completed

    Posted Oct 12, 2018 02:37 PM

    I confess I hardly ever use data partitions.