Skip to main content
Glama
javerthl

ServiceNow MCP Server

by javerthl

reorder_workflow_activities

Change the execution sequence of activities within a ServiceNow workflow by specifying the new order of activity IDs.

Instructions

Reorder activities in a workflow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activity_idsYesList of activity IDs in the desired order
workflow_idYesWorkflow ID or sys_id

Implementation Reference

  • The main handler function that implements the reorder_workflow_activities tool logic. It updates the 'order' field of each wf_activity record via ServiceNow REST API PATCH requests.
    def reorder_workflow_activities( auth_manager: AuthManager, server_config: ServerConfig, params: Dict[str, Any], ) -> Dict[str, Any]: """ Reorder activities in a workflow. Args: auth_manager: Authentication manager server_config: Server configuration params: Parameters for reordering workflow activities Returns: Dict[str, Any]: Result of the reordering operation """ # Unwrap parameters if needed params = _unwrap_params(params, ReorderWorkflowActivitiesParams) # Get the correct auth_manager and server_config try: auth_manager, server_config = _get_auth_and_config(auth_manager, server_config) except ValueError as e: logger.error(f"Error getting auth and config: {e}") return {"error": str(e)} workflow_id = params.get("workflow_id") if not workflow_id: return {"error": "Workflow ID is required"} activity_ids = params.get("activity_ids") if not activity_ids: return {"error": "Activity IDs are required"} # Make the API requests to update the order of each activity try: headers = auth_manager.get_headers() results = [] for i, activity_id in enumerate(activity_ids): # Calculate the new order value (100, 200, 300, etc.) new_order = (i + 1) * 100 url = f"{server_config.instance_url}/api/now/table/wf_activity/{activity_id}" data = {"order": new_order} try: response = requests.patch(url, headers=headers, json=data) response.raise_for_status() results.append({ "activity_id": activity_id, "new_order": new_order, "success": True, }) except requests.RequestException as e: logger.error(f"Error updating activity order: {e}") results.append({ "activity_id": activity_id, "error": str(e), "success": False, }) return { "message": "Activities reordered", "workflow_id": workflow_id, "results": results, } except Exception as e: logger.error(f"Unexpected error reordering workflow activities: {e}") return {"error": str(e)}
  • Pydantic model defining the input parameters for the reorder_workflow_activities tool: workflow_id and list of activity_ids.
    class ReorderWorkflowActivitiesParams(BaseModel): """Parameters for reordering workflow activities.""" workflow_id: str = Field(..., description="Workflow ID or sys_id") activity_ids: List[str] = Field(..., description="List of activity IDs in the desired order")
  • Registration of the tool in the get_tool_definitions dictionary, mapping the tool name to its handler, schema, description, etc., for MCP server integration.
    "reorder_workflow_activities": ( reorder_workflow_activities_tool, ReorderWorkflowActivitiesParams, str, "Reorder activities in a workflow", "str", # Tool returns simple message ),
  • Re-export of the reorder_workflow_activities function from workflow_tools in the tools package __init__.
    reorder_workflow_activities, update_workflow, update_workflow_activity, ) from servicenow_mcp.tools.story_tools import ( create_story, update_story, list_stories, list_story_dependencies, create_story_dependency, delete_story_dependency, ) from servicenow_mcp.tools.epic_tools import ( create_epic, update_epic, list_epics, ) from servicenow_mcp.tools.scrum_task_tools import ( create_scrum_task, update_scrum_task, list_scrum_tasks, ) from servicenow_mcp.tools.project_tools import ( create_project, update_project, list_projects, ) # from servicenow_mcp.tools.problem_tools import create_problem, update_problem # from servicenow_mcp.tools.request_tools import create_request, update_request __all__ = [ # Incident tools "create_incident", "update_incident", "add_comment", "resolve_incident", "list_incidents", # Catalog tools "list_catalog_items", "get_catalog_item", "list_catalog_categories", "create_catalog_category", "update_catalog_category", "move_catalog_items", "get_optimization_recommendations", "update_catalog_item", "create_catalog_item_variable", "list_catalog_item_variables", "update_catalog_item_variable", # Change management tools "create_change_request", "update_change_request", "list_change_requests", "get_change_request_details", "add_change_task", "submit_change_for_approval", "approve_change", "reject_change", # Workflow management tools "list_workflows", "get_workflow_details", "list_workflow_versions", "get_workflow_activities", "create_workflow", "update_workflow", "activate_workflow", "deactivate_workflow", "add_workflow_activity", "update_workflow_activity", "delete_workflow_activity", "reorder_workflow_activities",
  • Import alias used for the tool handler in tool_utils.py registration.
    reorder_workflow_activities as reorder_workflow_activities_tool,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/javerthl/servicenow-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server