case state changes to 4 when i cancel a workflow

Priyansh_98
Tera Guru

Hi all,

 

I am facing an issue with the wearied behaviour of the state field  on the csm case table,

when i cancel a workflow attached to a parent ticket, the state of the case table changes to 4.

 

i have investigated many script ,BR  and flows but didn't found the root cause, dose anyone have faced this issue in the past? or any one know how can i fix this issue?

 

here is a script i am using to cancel the workflow.

 function Cancel_Attached_Workflow() {
        var record_id = // sys_id of record

        var workflow_context = new GlideRecord('wf_context'); //Get the context of the workflow for given change request
        workflow_context.addEncodedQuery(record_id);
        workflow_context.query();
        while (workflow_context.next()) {
            var workflow = new Workflow();
            workflow.cancelContext(workflow_context);

        }
    }

 

Priyansh_98_0-1729170545482.png

if anyone have any suggestion please let me know..!!

3 REPLIES 3

Mark Manders
Mega Patron

I am checking on my OOB instance. On Task level, state 4 is closed incomplete. Case has no state '4'. Case also has no 'Closed incomplete' state. Somewhere in your workflow, or triggered by the cancelation, it is stated that the Case moves to 'Closed Incomplete' when this happens. Can it be that some one copied logic from another process (like Change Request) to do the same with cases?
Because when a task inherited table moves to a state it doesn't have, it will try to find that state on Task level. Moving your case to the non-existing closed incomplete state, finds that state on Task and sets the value (4).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders ,

 

Thanks for your response ..!!

on case level i am manually updating the state to cancelled. do you know like if we can avoid triggering BR and other script while cancelling the workflow to cancel.

You need to update the (work)flow to set the correct state. I don't know what is setting it, but as I mentioned: it looks to be a copy of something that already existed, without setting the correct status. You need to update your logic to set it to the correct value instead of 'closed incomplete'. 

When you manually update something, it will trigger rules/flows, so you really need to check on what is happening. 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark