example-reset-and-sample-scripts

This section provides example scripts for resetting the context menu configuration and seeding sample menu items for testing and demonstration purposes.

Comprehensive Example Templates

For complete, production-ready context menu implementations, see these detailed templates in the example scripts:

  • Comprehensive Workflow Integration Template - Advanced comprehensive template demonstrating all major MFSQL integration patterns including: - Complete parameter validation and error handling - Temporary table processing for complex operations - Valuelist item management and synchronization - Object relationship handling - Automated email notifications for error conditions - Batch processing optimizations - Complete audit trail and debugging support

  • custom DoCMObjectActionForWorkFlowState - Focused workflow state action template

  • custom DoCMObjectAction - Basic context menu object action template

  • Template - custom procedure - Minimal custom procedure template

Reset and Sample Menu Configuration

Note

Use these scripts carefully in development environments. Always backup your MFContextMenu table before applying reset scripts in production.

Reset Context Menu Table:

-- WARNING: This will remove all existing context menu items
TRUNCATE TABLE dbo.MFContextMenu;

Insert Sample Menu Structure:

-- Create sample menu headings
EXEC dbo.spMFContextMenuHeadingItem
    @MenuName = 'Development Templates',
    @PriorMenu = NULL,
    @IsRemove = 0,
    @UserGroup = 'ContextMenu';

EXEC dbo.spMFContextMenuHeadingItem
    @MenuName = 'Workflow Actions',
    @PriorMenu = 'Development Templates',
    @IsRemove = 0,
    @UserGroup = 'ContextMenu';

-- Add comprehensive template menu item
EXEC dbo.spMFContextMenuActionItem
    @ActionName = 'Comprehensive Workflow Template',
    @ProcedureName = 'custom.ComprehensiveWorkflowTemplate',
    @Description = 'Execute comprehensive workflow integration template',
    @RelatedMenu = 'Development Templates',
    @IsRemove = 0,
    @IsObjectContext = 1,
    @IsWeblink = 0,
    @IsAsynchronous = 1,
    @IsStateAction = 0,
    @PriorAction = NULL,
    @UserGroup = 'ContextMenu';

-- Add workflow state actions
EXEC dbo.spMFContextMenuActionItem
    @ActionName = 'StateAction_Comprehensive',
    @ProcedureName = 'custom.ComprehensiveWorkflowTemplate',
    @Description = 'Comprehensive workflow state change handler',
    @RelatedMenu = NULL,
    @IsRemove = 0,
    @IsObjectContext = 0,
    @IsWeblink = 0,
    @IsAsynchronous = 1,
    @IsStateAction = 1,
    @PriorAction = NULL,
    @UserGroup = 'ContextMenu';

Verify Menu Setup:

-- View created menu structure
SELECT
    cm.ID,
    cm.ActionName,
    cm.Action,
    cm.ActionType,
    cm.Message,
    cm.SortOrder,
    cm.ParentID,
    cm.IsAsync,
    ug.UserGroup
FROM dbo.MFContextMenu cm
LEFT JOIN dbo.MFvwUserGroup ug ON cm.UserGroupID = ug.ID
ORDER BY cm.ParentID, cm.SortOrder;

Testing and Validation

After setting up the sample menu items:

  1. Test Menu Visibility: Verify menu items appear for users in the ContextMenu group

  2. Test Procedure Execution: Execute menu actions and verify logging in MFProcessBatch

  3. Test Error Handling: Trigger errors intentionally and verify error logging works

  4. Test Workflow Integration: Set up workflow state actions using the StateAction items

Sample Testing Scripts:

-- Check process batch logs after execution
SELECT TOP 10
    pb.ProcessType,
    pb.LogText,
    pb.LogStatus,
    pb.Created,
    pbd.LogProcedureStep,
    pbd.LogText AS DetailText
FROM dbo.MFProcessBatch pb
LEFT JOIN dbo.MFProcessBatchDetail pbd ON pb.ProcessBatch_ID = pbd.ProcessBatch_ID
WHERE pb.ProcessType LIKE '%Comprehensive%'
ORDER BY pb.Created DESC, pbd.ID;

-- Check for any errors in the log
SELECT * FROM dbo.MFLog
WHERE SPName LIKE '%Comprehensive%'
ORDER BY ID DESC;

Development Guidelines

When developing custom context menu procedures:

  1. Start with Templates: Begin with the comprehensive template and remove unused sections

  2. Implement Logging: Always use ProcessBatch logging for audit trails

  3. Handle Errors Gracefully: Implement comprehensive error handling

  4. Test Thoroughly: Test with various object types and failure scenarios

  5. Document Customizations: Update procedure headers with specific implementation details

  6. Security Review: Ensure all dynamic SQL follows security best practices