{"record":{"id":"a9f4ef32f94c3aca","repo":"pentaho/pentaho-kettle","slug":"alert-dialog-cancelled-by-user","errorCode":null,"errorMessage":"Alert dialog cancelled by user.","messagePattern":"Alert dialog cancelled by user\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1573,"sourceCode":"        return objForReplace;\n      } else {\n        throw Context.reportRuntimeError( \"The function call replace is not valid (wrong number of arguments)\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"Function call replace is not valid : \" + e.getMessage() );\n    }\n  }\n\n  // Implementation of the JS AlertBox\n  public static String Alert( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    SpoonInterface spoon = SpoonFactory.getInstance();\n    if ( ArgList.length == 1 && spoon != null ) {\n      String strMessage = Context.toString( ArgList[0] );\n      boolean ok = spoon.messageBox( strMessage, \"Alert\", true, Const.INFO );\n      if ( !ok ) {\n        throw new RuntimeException( \"Alert dialog cancelled by user.\" );\n      }\n    }\n\n    return \"\";\n  }\n\n  // Setting EnvironmentVar\n  public static void setEnvironmentVar( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    String sArg1 = \"\";\n    String sArg2 = \"\";\n    if ( ArgList.length == 2 ) {\n      try {\n        sArg1 = Context.toString( ArgList[0] );\n        sArg2 = Context.toString( ArgList[1] );\n        System.setProperty( sArg1, sArg2 );\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( e.toString() );","sourceCodeStart":1555,"sourceCodeEnd":1591,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1555-L1591","documentation":"The ScriptValuesMod `Alert(message)` function shows a modal message box via the Spoon UI (SpoonFactory.getInstance().messageBox). If the user closes/cancels the dialog instead of confirming, the function throws this RuntimeException to abort the transformation run.","triggerScenarios":"Calling Alert('some message') inside a JavaScript step while running in Spoon, and the user clicks Cancel/closes the alert dialog instead of OK.","commonSituations":"Interactive debugging in Spoon where a tester dismisses the box; scheduled/headless executions where spoon is null — note in that case the function silently returns '' instead of throwing; a user misunderstanding that Cancel aborts the step.","solutions":["Re-run and click OK instead of cancelling the dialog","Remove or gate the Alert() call before production/scheduled runs (it requires interactive UI)","Replace Alert with a log statement (e.g. write to a field or use the 'Write To Log' step) for non-interactive use"],"exampleFix":"// before\nAlert('Row: ' + rowNum);\n// after\nwriteToLog('Row: ' + rowNum); // or remove the call\n","handlingStrategy":"try-catch","validationCode":"// Ensure the step only runs interactively in Spoon\nif (SpoonFactory.getInstance() == null) {\n  // headless run: skip Alert, log instead\n}","typeGuard":"function canAlert() { return SpoonFactory.getInstance() != null; }","tryCatchPattern":"try {\n  Alert('message');\n} catch (e) {\n  if (String(e).indexOf('Alert dialog cancelled') !== -1) {\n    // user cancelled: treat as abort or continue per requirements\n  } else { throw e; }\n}","preventionTips":["Never leave Alert() in production/scheduled transformations","Use 'Write To Log' step or writeToLog() instead of modal dialogs","Communicate to testers that cancelling the alert aborts the step"],"tags":["javascript","pentaho","ui","user-cancelled"],"backgroundTag":"user-cancelled-operation","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}