Lexmark X925 Lexmark Document Distributor - Page 20

Adding a library script to a solution, Accessing the functions of a library script

Page 20 highlights

Developing workflow solutions 20 The script file library.js in the TestSNS example template is an example of a library script. Adding a library script to a solution A library script does not require a specific file name. To begin adding a library script, add a blank script in the scripts\ folder. To define the script as a library script, a specific structure is used: • Begin the library section of the script with an empty library() function. • Use the format library.prototype. = function() for function headers. • Create a new library object. This must be done as the last line of the script. The following example shows the basic structure of a library script: function library() { } ... library.prototype.myFunction = function(myArgument1,myArgument2) { ... } ... new library(); Accessing the functions of a library script To access the functions of a library script from another script, create an object reference to the library script using the context.callTask() method. The functions in the library script are then available as members of the new object. The first argument in the callTask() method is always taskInfo.solutionName. The second argument is the script file name with no extension. For example, if the previous library script is named "mylibrary.js," the following line creates an object reference to that library: var myLib = context.callTask(taskInfo.solutionName, "mylibrary"); The included functions can then be accessed as follows: myLib.myFunction(arg1,arg2) Using auto-configure scripts If you have detailed knowledge of the LDD system where a solution will be deployed, then you can write an auto‑configure script that can: • Create a device group. • Add printers to a device group. • Deploy the solution to a device group. • Configure home screens. • Discover devices. • Perform a policy update. • Set the server online.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82

The script file library.js in the TestSNS example template is an example of a library script.
Adding a library script to a solution
A library script does not require a specific file name. To begin adding a library script, add a blank script in the scripts\
folder.
To define the script as a library script, a specific structure is used:
Begin the library section of the script with an empty
library()
function.
Use the format
library.prototype.<functionName> = function(<arguments>)
for function
headers.
Create a new
library
object. This
must
be done as the last line of the script.
The following example shows the basic structure of a library script:
function library()
{
}
library.prototype.myFunction = function(myArgument1,myArgument2)
{
}
new library();
Accessing the functions of a library script
To access the functions of a library script from another script, create an object reference to the library script using the
context.callTask()
method. The functions in the library script are then available as members of the new object.
The first argument in the
callTask()
method is always
taskInfo.solutionName
. The second argument is the
script file name with no extension. For example, if the previous library script is named “mylibrary.js,” the following line
creates an object reference to that library:
var myLib = context.callTask(taskInfo.solutionName, "mylibrary");
The included functions can then be accessed as follows:
myLib.myFunction(arg1,arg2)
Using auto-configure scripts
If you have detailed knowledge of the LDD system where a solution will be deployed, then you can write an
auto
configure script that can:
Create a device group.
Add printers to a device group.
Deploy the solution to a device group.
Configure home screens.
Discover devices.
Perform a policy update.
Set the server online.
Developing workflow solutions
20