Custom Keywords take screenshot when failing

All you need to do is to catch Exceptions and take screenshots in the catch clause:

try {
  WebUI.callTestcase(...)  
} catch(Exception e) {
  WebUI.takeScreenshot(file)
  // throw e // perhaps?
}

See also