Automatic Sign-On Macro for Mainframes

In this example the Autosignon object is used to create a macro that uses the credentials associated with a user to obtain a pass ticket from the Digital Certificate Access Server (DCAS).

var macro = createMacro(function*() {
    'use strict';

    // Obtain the PresentationSpace for interacting with the host
    var ps = session.getPresentationSpace();
    
    // Variable for login pass ticket
    var passTicket;
    
    // Login application ID
    var appId = 'CICSV41A';

    // Set the default timeout for "wait" functions
    wait.setDefaultTimeout(10000);

    // Begin Generated Macro
    try {
        yield wait.forCursor(new Position(24, 2));
        
        // Obtain a pass ticket from DCAS.
        passTicket = yield autoSignon.getPassTicket(appId);
        
        ps.sendKeys('cics');
        ps.sendKeys(ControlKey.ENTER);

        yield wait.forCursor(new Position(10, 26));
        
        // Replace generated username with sendUserName(passTicket) ... 
        yield autoSignon.sendUserName(passTicket);
        
        // ps.sendKeys('bvtst01' + ControlKey.TAB + ControlKey.TAB);        
        ps.sendKeys(ControlKey.TAB + ControlKey.TAB);
        
        yield wait.forCursor(new Position(11, 26));
        
        // Replace generated password with sendPassword(passTicket) ...
        yield autoSignon.sendPassword(passTicket);
        
        // var userInput3 = yield ui.prompt('Password:', '', true);
        // if (userInput3 === null) {
            // throw new Error('Password not provided');
        // }
        // ps.sendKeys(userInput3);
        ps.sendKeys(ControlKey.ENTER);

        yield wait.forCursor(new Position(1, 1));
        yield ui.message('Logged in. Log me off.');
        ps.sendKeys('cesf logoff');
        ps.sendKeys(ControlKey.ENTER);
    } catch (error) {
        yield ui.message(error);
    }
    //End Generated Macro
});

// Run the macro
return macro();