Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

reorder_workflow_activities

Reorder activities in a ServiceNow workflow by specifying the workflow ID and desired activity sequence.

Instructions

Reorder activities in a workflow

Input Schema

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

Implementation Reference

  • The main execution function for the reorder_workflow_activities tool. It updates the 'order' field on wf_activity records via the ServiceNow REST API to reorder activities based on the provided list of activity IDs.
    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 BaseModel defining the input schema/parameters for the reorder_workflow_activities tool.
    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")
  • Tool registration entry in the central tool_definitions dictionary, mapping the tool name to its handler, params schema, return type, description, and serialization method.
    "reorder_workflow_activities": ( reorder_workflow_activities_tool, ReorderWorkflowActivitiesParams, str, "Reorder activities in a workflow", "str", # Tool returns simple message ),
  • Imports the handler function and params schema from workflow_tools.py, aliasing the function for use in registration.
    from servicenow_mcp.tools.workflow_tools import ( ActivateWorkflowParams, AddWorkflowActivityParams, CreateWorkflowParams, DeactivateWorkflowParams, DeleteWorkflowActivityParams, GetWorkflowActivitiesParams, GetWorkflowDetailsParams, ListWorkflowsParams, ListWorkflowVersionsParams, ReorderWorkflowActivitiesParams, UpdateWorkflowActivityParams, UpdateWorkflowParams, ) from servicenow_mcp.tools.workflow_tools import ( activate_workflow as activate_workflow_tool, ) from servicenow_mcp.tools.workflow_tools import ( add_workflow_activity as add_workflow_activity_tool, ) from servicenow_mcp.tools.workflow_tools import ( create_workflow as create_workflow_tool, ) from servicenow_mcp.tools.workflow_tools import ( deactivate_workflow as deactivate_workflow_tool, ) from servicenow_mcp.tools.workflow_tools import ( delete_workflow_activity as delete_workflow_activity_tool, ) from servicenow_mcp.tools.workflow_tools import ( get_workflow_activities as get_workflow_activities_tool, ) from servicenow_mcp.tools.workflow_tools import ( get_workflow_details as get_workflow_details_tool, ) from servicenow_mcp.tools.workflow_tools import ( list_workflow_versions as list_workflow_versions_tool, ) from servicenow_mcp.tools.workflow_tools import ( list_workflows as list_workflows_tool, ) from servicenow_mcp.tools.workflow_tools import ( reorder_workflow_activities as reorder_workflow_activities_tool,
  • Re-export of the reorder_workflow_activities function and inclusion in __all__ for easy access from the tools package.
    from servicenow_mcp.tools.workflow_tools import ( activate_workflow, add_workflow_activity, create_workflow, deactivate_workflow, delete_workflow_activity, get_workflow_activities, get_workflow_details, list_workflow_versions, list_workflows, 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",

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/JLKmach/servicenow-mcp'

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