ERROR Test failed: Can't find method com.snc.automation.TriggerSynchronizer.executeNow(string).

Ron28
Mega Sage

I just ran into this error while creating an ATF test to start a Discovery schedule.

When putting the following code in a background script, this works fine:

var schedule = 'fcc83251db4829185c863ec3f39619b6';

var grSched = new GlideRecord('discovery_schedule');		// Need to pass reference to Discovery script include
grSched.get(schedule);								        // Get Schedule record

var d = new Discovery();
var sta = d.discoverNow(grSched);

var grStatus = new GlideRecord('discovery_status');
grStatus.get(sta);

gs.print('Discovery Status Record number: ' + grStatus.getValue('number'));

// Output:
//*** Script: Discovery Status Record number: DIS4073844

 

But when running this near enough identical code via an ATF test in a scripted step I get the above error on the call to the Discovery script include, discoverNow() method:

(function executeStep(inputs, outputs, stepResult, timeout) {
	var schedule = 'fcc83251db4829185c863ec3f39619b6';
	var grSched = new GlideRecord('discovery_schedule');

	var d = new Discovery();
	var status = d.discoverNow(schedule); 				// Returns sys_id of Discovery Status record


I've hardcoded the sys_id of the schedule here only to have an identical call to the Discovery script include. 
The error:

ERROR Test failed: Can't find method com.snc.automation.TriggerSynchronizer.executeNow(string). (sys_script_include.a6cdaf5bc0a802550004f460b6c04967.script; line 46)
	org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:58)
	org.mozilla.javascript.Context.reportRuntimeError(Context.java:1570)


Thinking this was a scope issue I checked all components:

test 
re-usable test
scripted step
script include

are all in the Global app scope. The script include is unmodified, OOB. 

Any ideas what is going wrong?

 

Thanks
Ron

 

 

1 ACCEPTED SOLUTION

bonjarney
Mega Contributor

The error message is telling you the answer — it's likely a parameter type problem, not a sandbox problem.

Read the error carefully: Can't find method executeNow(string). It's not saying "access denied" or "class not found." It's saying it can't find an executeNow method that accepts a string parameter.

Your working background script passes a GlideRecord to discoverNow(). Most ATF attempts pass a string sys_id. The underlying Java class (SncTriggerSynchronizer.executeNow()) may simply not have a string overload.

2-minute test to confirm — run this in Background Scripts:

(function() {
    var grSched = new GlideRecord('discovery_schedule');
    grSched.setLimit(1);
    grSched.query();
    if (!grSched.next()) {
        gs.info('No discovery_schedule records found.');
        return;
    }
    var schedSysId = grSched.getUniqueValue();
    gs.info('Testing with STRING parameter...');
    try {
        new Discovery().discoverNow(schedSysId); // STRING
        gs.info('String worked — sandbox is the real issue.');
    } catch (e) {
        gs.info('String FAILED: ' + e.message);
        gs.info('Now test with GlideRecord in your ATF step.');
    }
})();
 

If the string fails here too â€” the root cause is parameter type, not sandbox. Fix your ATF step to query the schedule as a GlideRecord first, then pass it:

// ATF "Run Server Side Script" step — fixed
(function(outputs, steps, params, stepResult) {
    var grSched = new GlideRecord('discovery_schedule');
    grSched.get('YOUR_SCHEDULE_SYS_ID');
    var d = new Discovery();
    d.discoverNow(grSched); // GlideRecord, NOT string
    stepResult.setOutputMessage('Discovery triggered.');
    stepResult.setSuccess();
})(outputs, steps, params, stepResult);
 

If the string works in background scripts â€” then the sandbox restriction is real and the parameter type isn't the issue. In that case, ATF is the wrong tool for triggering Discovery on a schedule. Use a Scheduled Script Execution (sysauto_script) to run Discovery daily in unrestricted server context, and use ATF only to validate that Discovery ran (query discovery_status for today's record). Separate execution from validation — ATF is a test framework, not a scheduler.

View solution in original post

8 REPLIES 8

Tanushree Maiti
Kilo Patron

Hi @Ron28 

 

Make sure you have role  discovery_adminor admin .

 

Also you can refer: 

 

https://www.servicenow.com/community/developer-forum/snctriggersynchronizer-executenow-is-not-workin...

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ron28
Mega Sage

I do have both discovery_admin and admin roles.

In the re-usable test I added a step to impersonate myself, to be sure whatever user runs the test has the roles. The impersonation step is successful but it does not resolve the issue.

What scenario does your test actually cover? The SncTriggerSynchronizer (used to start the background job) class is not available and I doubt you can get it to be. You could try a ui step that clicks the Discover now ui action on the schedule form and see if that works but I don't really understand what the test is for

Ron28
Mega Sage

The test runs an existing Discovery schedule in the same way these are run daily. They aren't run from a UI. I would think the initial creator of this script used that to avoid performance issues. Unfortunately the script wasn't finished and landed on my desk. I don't know what should or should not work, therefore checked if this would work in a background script which it does without any issue. But in the Global app scope from an ATF test step it won't due to this error.