Using Audit trail in a Scheduled Task

3
Hi Im using a Scheduled Task to create new entities and then change them to a number of different statuses depending on the information. I use The Audit trail module to keep track of all of the entities changes. The problem is that the AuditTrail.BCo_AudittrailSuperClass' for activity 'Create log' breaks on line 36 because on a NullPointerException for this.userObject = this.context.getSession().getUser().getMendixObject(); It looks like when i run these microflows from a scheduled task the audit trail cant get the userObject. How would i fix this? Stack Trace com.mendix.core.CoreException: Exception occurred in action 'Microflow [ShortApp.BatchSMSAfterUptime]', all database changes executed by this action were rolled back at com.mendix.core.actionmanagement.CoreAction.d(SourceFile:553) Caused by: com.mendix.core.CoreException: Exception occurred in microflow 'ShortApp.BatchSMSAfterUptime' for activity 'NestedLoopedMicroflow', all database changes executed by this microflow were rolled back at kM.b(SourceFile:252) Caused by: com.mendix.core.CoreException: Exception occurred in microflow 'ShortApp.BatchSMSAfterUptime.nested.1098455' for activity 'Call 'SMSBlazeProcess'', all database changes executed by this microflow were rolled back at kM.b(SourceFile:252) Caused by: com.mendix.core.CoreException: Exception occurred in microflow 'ShortApp.SMSBlazeProcess' for activity 'Change 'NewApplication' (ApplicationDate, ChannelInitiatedFrom, Application_Company, IDNumber, Surname, Initials, Cellphone, Application_Promotion, Application_ShortCodePromotion, DateOfBirth, Gender, Application_Store, CompanyCode, CompanyName, POSAccountType, Title_Helper, IDDocType, Title, Title_Helper_Enabled, ApplicationStatus, ApplicationStatus)', all database changes executed by this microflow were rolled back at kM.b(SourceFile:252) Caused by: com.mendix.core.CoreException: Exception occurred in microflow 'AuditTrail.BCo_AudittrailSuperClass' for activity 'Create log', all database changes executed by this microflow were rolled back at kM.b(SourceFile:252) Caused by: com.mendix.core.CoreException: Exception occurred in microflow 'AuditTrail.CreateLogForAudittrailSuperClass' for activity 'Log changes', all database changes executed by this microflow were rolled back at kM.b(SourceFile:252) Caused by: com.mendix.core.CoreException: java.lang.NullPointerException at it.b(SourceFile:167) Caused by: java.lang.NullPointerException at audittrail.log.CreateLog.<init>(CreateLog.java:36) at audittrail.actions.CreateAudittrailSuperClassLog.executeAction(CreateAudittrailSuperClassLog.java:41) at audittrail.actions.CreateAudittrailSuperClassLog.executeAction(CreateAudittrailSuperClassLog.java:21) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:155) at com.mendix.core.Core.execute(SourceFile:191) at hi.a(SourceFile:70) at kM.a(SourceFile:67) at eR.executeAction(SourceFile:96) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:155) at com.mendix.core.Core.executeSync(SourceFile:167) at is.a(SourceFile:71) at kM.a(SourceFile:67) at eR.executeAction(SourceFile:96) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:155) at com.mendix.core.Core.executeSync(SourceFile:167) at er.f(SourceFile:74) at er.a(SourceFile:35) at dj.execute(SourceFile:106) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:159) at com.mendix.core.Core.commit(SourceFile:478) at u.a(SourceFile:97) at kM.a(SourceFile:72) at eR.executeAction(SourceFile:96) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:155) at com.mendix.core.Core.executeSync(SourceFile:167) at is.a(SourceFile:71) at kM.a(SourceFile:67) at eR.executeAction(SourceFile:96) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:155) at com.mendix.core.Core.executeSync(SourceFile:167) at dK.a(SourceFile:68) at kM.a(SourceFile:67) at eR.executeAction(SourceFile:96) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:49) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:473) at it.b(SourceFile:155) at com.mendix.core.Core.execute(SourceFile:191) at F.a(SourceFile:104) at F.run(SourceFile:79) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)
asked
1 answers
3

That makes a lot of sense since your session will simply not have a user object when running as a scheduled event. Which user did you hope to retrieve?

Edit: I don't know if this audittrail module can handle empty values for the user but as Michel mentioned, a null check on the user before trying to get the mendix object of the user should fix this if this module can deal with those values. Alternatively you could retrieve an admin user and set that as the user in this case.

answered