Debugging with the Trace Method

You can use the trace method to debug your policy scripts. With the trace method, you can test your script and see what values are calculated or set.

The trace method takes a single string. The policy script screen logs and displays this string when you click Test. For non-string values, use toString().

For example, the starter script uses the trace method a couple of times:

Copy
if(!context.onPrem){

trace("not onprem");

var umod = module('User');

var user = umod.GetCurrentUser();

if(user.InRole("sysadmin")){

trace("allow sysadmin");

policy.RequiredLevel = 2;

} else {

trace("block non sysadim");

policy.Locked = true;

}

}

For example, if you run this script as a member of the sysadmin role and you haven’t specified the Corporate IP range, you see the following result:

If you’re within the corporate intranet, you see no trace results because the starter script mainly handles situations where the user is not logged in to the corporate intranet.