Electrical maintenance work was being performed on an elevator just hours before it malfunctioned, killing an advertising executive in Midtown, a spokesman for New York City’s Buildings Department said Thursday.