Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

ConnectionInfoProvider returns null

rripamonti
Tera Contributor

Hello everyone,

I'm struggling to understand what is wrong with `ConnectionInforProvider`.

I'm using it in a Script Include that is trying to get a Bearer token from an API endpoint.

function getAuthorizationToken(aliasId) {
	var token = undefined;
	var provider = new sn_cc.ConnectionInfoProvider();
	var connectionInfo = null;
	try {
		connectionInfo = provider.getConnectionInfoByDomain(aliasId, 'global');
	} catch(e) {
		gs.error(JSON.stringify(e));
	}
	if (connectionInfo == null) {
		try {
			connectionInfo = provider.getConnectionInfoByDomain(aliasId, 'e4872febdbc29010ece1a0f2ca961940');
		} catch(e) {
			gs.error(JSON.stringify(e));
		}
	}
	if (connectionInfo == null) {
		try {
			connectionInfo = provider.getConnectionInfo(aliasId);
		} catch(e) {
			gs.error(JSON.stringify(e));
		}
	}
	var username = connectionInfo.getCredentialAttribute('user_name');
       // REST OF THE CODE IS OMITTED DUE TO OUT OF SCOPE
}

This script is used inside a Data Source, which is also used in a Scheduled Data Import.

If opening the Data Source, I click on `Test Load 20 Records`, it works fine - credentials are retrieved and the token is generated correctly.

Instead, if opening the Scheduled Data Import, I click on `Execute Now`, it won't work, and, checking the logs the following exception is thrown (note: the line corresponds to `var username = connectionInfo.getCredentialAttribute('user_name')`).

Spoiler
com.glide.db.impex.custom.CustomLoader: com.glide.db.impex.datasource.DataSourceException: TypeError: Cannot convert null to an object. (sys_script_include.525b07321b2fb110567755342a4bcb87.script; line 24): com.glide.db.impex.custom.CustomLoader.loadDataFromScript(CustomLoader.java:87) com.glide.db.impex.custom.CustomLoader.load(CustomLoader.java:58) com.glide.db.impex.AbstractLoader.startWork(AbstractLoader.java:167) com.glide.worker.AbstractProgressWorker.startAndWait(AbstractProgressWorker.java:131) com.glide.worker.HierarchicalProgressWorker.startAndWait(HierarchicalProgressWorker.java:26) com.glide.worker.AbstractProgressWorker.start(AbstractProgressWorker.java:106) com.glide.system_import_set.ImportSetLoader.startWorker(ImportSetLoader.java:141) com.glide.system_import_set.ImportSetLoader.startLoader(ImportSetLoader.java:130) com.glide.system_import_set.ImportSetLoader.loadImportSetTable(ImportSetLoader.java:114) com.snc.automation.ScheduledImportSetJob.doConcurrentImport(ScheduledImportSetJob.java:275) com.snc.automation.ScheduledImportSetJob.runImport(ScheduledImportSetJob.java:108) com.snc.automation.ScheduledImportSetJob.runNextImport(ScheduledImportSetJob.java:83) com.snc.automation.ScheduledImportSetJob.runImport(ScheduledImportSetJob.java:60) com.snc.automation.ScheduledImportJob.execute(ScheduledImportJob.java:66) com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:169) com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:172) com.glide.schedule.JobExecutor.execute(JobExecutor.java:155) com.glide.schedule.JobExecutor.execute(JobExecutor.java:149) com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:449) com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$1(SchedulerWorkerThread.java:318) com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35) com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:318) com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:118)

Has anyone encountered such issue before?

 

Thanks for the help!

0 REPLIES 0