Assignment Client Scripting


#1

Assignment Client Script has an Assignment Client Log. But, why does it print the entire strigified contents of the .js and it does not print the message?

[12/19 11:24:19] [INFO] [default] [6548] [agent] Downloaded script:
 "(function() { \r\nprint('Hello Assignment Client.');\r\n });"

#2

I think the contents of AC .js scripts are just logged for debugging the fetching process.

Your print message isn’t output because the whole script boils down into:

function anonymous() {
  print('Hello Assignment Client.');
}

(ie: a function gets declared… but never called)

Unfortunately, the recommended convention for Entity Scripts is like your example – wrapping an anonymous function in parens to make it an expression. But that’s an anti-pattern that should be avoided whenever possible.

Fortunately, with AC and Client scripts you can instead just use standard JavaScript conventions when structuring your code. Maybe try one of these variations:

(function() {
  print('Hello Assignment Client.');
})(); // immediately invoke the anonymous function
function main() {
  print('Hello Assignment Client.');
}
main(); // explicitly call as a named function