- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi I need to update the state field for our SC Tasks via the REST API but the field is protected I assume by a workflow and can only be updated by the UI Action buttons "In Progress", "Close Task" and "Cancel".
How can I trigger these UI Actions for specific SC Task numbers via the API?
I've asked various AI bots and some say you cant do it, some say can but then have hallucinated false ways of doing so
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Found the solution on a blog to which I cannot add the link to, but here is the solution:
Call UI actions with REST using ServiceNow OOTB way – UPDATED
Now you can execute UI Actions using OOTB REST API.
Note: this out of the box method is only available from Madrid version and up, if you are using prior versions click here.
There is only one endpoint to do POST call for UI actions.
POST @ /api/now/ui/ui_action/${sys_id_of_UI_action}
Additionaly, there are same 3 mandatory body parameters:
sysparm_table – table name of UI action.
sysparm_sys_id – sys_id of the record you want to run UI action against.
api=api (this has to be static).
If your UI action is designed to take additional parameters, you can pass them as well.
Note, if this is not working, you might need to set up Request header with Content-Type application/json and pass body parameters as following:
{
"fields": [ { "name": "" } ]
}
Also, if your UI action contains client side only code, like g_form, it has to be converted to server side for this to work, because without user session being present, g_form and other client side API’s will be equal to null.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Try this,
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
It should allow update but if field is marked Readonly at dictionary then it won't allow.
Also check if any data policy is blocking that field update.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi Ankur
I have asked our client if the read-only can be removed from the state field but not expecting a quick answer from them.
However, I was hoping there was a way to trigger those buttons or the workflow behind them using the API. There was hint in this post on doing this but the poster wanted to do it on the table level rather than the record level. I am looking to do it on the record (SC Task) level but not exactly sure how to make the API call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
Hi @ykara
Note : The below suggestion given by Product Documentation ServiceNow.. Summarized by AI
You essentially have three options:
1. Call the same business logic that the UI Action calls
-
Each of those buttons (In Progress, Close Task, Cancel) is backed by either:
-
A UI Action script, or
-
A Flow/Business Rule triggered by the UI Action.
-
-
Inspect the UI Action record for
sc_task
(System UI > UI Actions). -
You’ll see a script that might be calling
task.setWorkflow(...)
, updating state, and running extra logic (notifications, approvals, etc.). -
You can refactor that script into a Script Include (API-safe), then call it via REST (using
GlideAjax
or a custom scripted REST API).
This is the most maintainable approach.
2. Expose a Scripted REST API wrapper
-
Create a Scripted REST API called, for example,
TaskStateAPI
. -
Define an endpoint like
POST /change_state
. -
In the script, accept parameters (
task_number
,action
), look up the task, and then call the same logic the UI Action does:(function process(request, response) { var taskNum = request.queryParams.task_number; var action = request.queryParams.action; // in_progress, close, cancel var task = new GlideRecord('sc_task'); if (task.get('number', taskNum)) { if (action == "in_progress") { task.state = 2; // In Progress // plus any extra logic UI Action does } else if (action == "close") { task.state = 3; // Closed Complete } else if (action == "cancel") { task.state = 4; // Closed Incomplete } task.update(); response.setBody({result: "Updated"}); } else { response.setBody({error: "Task not found"}); } })(request, response);
-
From your external system, call this REST API instead of the Table API.
3. If absolutely required: direct Table API update (not recommended)
-
You can force
PATCH /api/now/table/sc_task
with{ "state": "3" }
, if you disable/alter the protection Business Rule. -
But you’ll skip all the logic tied to the UI Action (like notifications, catalog item updates, or parent RITM closure).
-
This risks data inconsistency. Only use if you truly don’t care about the workflows.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi Ravi
Is there not a way of just calling the UI Action buttons or triggering the associated workflow via the API?
There was hint in this post on doing this but the poster wanted to do it on the table level rather than the record level. I am looking to do it on the record (SC Task) level but not exactly sure how to make the API call