Hiow to stop workflow execution for an Item

Michael51
Tera Guru

Hello All,

We are generating a request through a script using the cart API and simultaneously inserting an approval record for the same request and we are auto-approving these requests via business rules (BR), so once request is Approved RITM's Workflow is getting quicked off and working as expected 

I want to avoid/stop Workflow which is running on Request Table because In the workflow we have condition if that doesn't match it cancels the request and move this to Cancelled state after workflow execution my BR is running and updating the state to Work In progress and making the request to Active but it is updating worklog as cancelled so In order to avoid that I had thought to design below solution 

 

My initial plan was to create a true/false field on the Request Table and set it to true using the Cart API while creating request and that to the trigger condition in workflow but Unfortunately, I have been unable to find a way to set the value for the request. After the request is generated via the cart API, it seems we can update any information related to the request.

 

can anyone suggest solution to achieve this 

 

@Ankur Bawiskar @Vishal Birajdar 

5 REPLIES 5

Amit Gujarathi
Giga Sage
Giga Sage

HI @Michael51 ,
I trust you are doing great.

  1. Using a True/False Field: Your idea of using a true/false field on the Request Table is a good one. This field can act as a flag to determine whether the workflow should run or not.

  2. Setting the Field Value: Since you're facing challenges setting the value during request creation via the cart API, consider the following approach:

    • Business Rule (Before Insert): Create a 'Before Insert' business rule on the Request Table. This BR will check if the request is being created via the cart API (you can identify this based on certain unique attributes of such requests). If it is, set the true/false field to 'true'.
  3. Modify the Workflow: Update the workflow's trigger condition to check the value of the true/false field. If the field is set to 'true', the workflow should not run. This will ensure that the workflow is bypassed for requests created via the cart API.

  4. Post-Creation Update: If you need to update any other information related to the request after it's generated via the cart API, you can use a scheduled job or a business rule that runs on update to make the necessary changes based on your conditions.

  5. Testing: Once these changes are implemented, thoroughly test the entire process to ensure that the workflow is bypassed as expected and that there are no unintended side effects.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



@Amit Gujarathi ,

I'm doing good and hope your doing good too:) 

Thank you for responding on this and Providing Insights

 

So let me be more clear so I have designed script in Scripted SOAP API in dynamic way such that they need to pass sysid of the item along with variable data then API does the JOb , so user can create use any item to create the request 

 

  • Business Rule (Before Insert): Create a 'Before Insert' business rule on the Request Table. This BR will check if the request is being created via the cart API (you can identify this based on certain unique attributes of such requests). If it is, set the true/false field to 'true'. - can you please provide more insight on this according to my description above

Ankur Bawiskar
Tera Patron
Tera Patron

@Michael51 

did you try to use setWorkflow(false) and setUseEngines(false) in the script which you are using?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

No Ankur , I didnt use setWorkflow(false) 

 

I'm creating Approval record in SOAP API script and then approving the same via BR 

 

where do I need to use them