tw.system.executeServiceByName(name, inputs) runs a service (service flow / general system service) from a server-side script and returns its outputs - useful for dynamic dispatch (the service to run is decided by data). Signature and use:
// server-side script (service flow / BPD script task)
var inputs = new tw.object.Map(); // inputs by parameter name
inputs.put("customerId", tw.local.order.customerId);
inputs.put("includeHistory", true);
var result = tw.system.executeServiceByName("Get Customer Details", inputs); // name of the service in the same process app or a dependent toolkit
tw.local.customer = result.get("customer"); // outputs come back as a Map keyed by output parameter name
tw.local.found = result.get("found");
// dynamic dispatch: service name from configuration
var handler = tw.epv.Routing["handler_" + tw.local.order.type]; // e.g. "Handle Standard Order" / "Handle Express Order"
var out = tw.system.executeServiceByName(handler, inputs);Details: inputs are matched by parameter name (unmatched inputs are ignored, missing ones get defaults); business objects are passed by reference to the called service, which runs synchronously in the same transaction and thread; errors thrown inside surface as JavaScript exceptions in the caller (wrap with try / catch); the service is resolved in the current snapshot (toolkit services included). Not available in client-side scripts (browser) - there use a service flow call from the CSHS or the Service Call control. Prefer a modelled nested service call when the target is static: it is visible in the diagram, validated, and refactoring-safe; executeServiceByName is for genuinely dynamic cases, and renaming a service silently breaks callers - keep the names in one EPV.
References