calworkminutesplugin is working fine in expression rule. But when i call the expression rule from the process model getting the below error message.
Expression evaluation error in rule 'xxxxx' at function 'calworkminutesplugin' [line xx: ) (Data Outputs)
Any Suggestions Please.
Discussion posts and replies are publicly visible
Did you check the tomcat-stdout log file for any details?
Hi Stefan, thanks for quick response.
the log file showing as below:
Caused by: java.lang.NullPointerException at com.appiancorp.ps.plugins.calendarfunctions.CalendarHelper.initializeCalendar(CalendarHelper.java:47) at com.appiancorp.ps.plugins.calendarfunctions.CalWorkMinutesPlugin.CalWorkMinutesPlugin(CalWorkMinutesPlugin.java:36) at sun.reflect.GeneratedMethodAccessor4564.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.appiancorp.process.expression.CustomFunction$1.call(CustomFunction.java:846) at com.appiancorp.common.ContextClassLoaderSwitcher.runInContext(ContextClassLoaderSwitcher.java:27) at com.appiancorp.process.expression.CustomFunction.evaluate(CustomFunction.java:840) at com.appiancorp.process.expression.CustomFunction.evalDynamic0(CustomFunction.java:248) at com.appiancorp.process.expression.CustomFunction.lambda$evalDynamic$0(CustomFunction.java:240) at com.appiancorp.plugins.PluginUsageLogger.callWithPluginInformation(PluginUsageLogger.java:39) at com.appiancorp.process.expression.CustomFunction.evalDynamic(CustomFunction.java:239) at com.appiancorp.process.expression.CustomFunction.eval0(CustomFunction.java:208) at com.appiancorp.core.expr.DefaultEvaluable.eval(DefaultEvaluable.java:214) at com.appiancorp.process.expression.ExpressionEvaluator.evaluate(ExpressionEvaluator.java:314) at com.appiancorp.core.expr.FunctionCallDelegate$ExternalFunctionCallWithContext.evaluateCustomerPluginFunction(FunctionCallDelegate.java:395) at com.appiancorp.core.expr.FunctionCallDelegate$ExternalFunctionCallWithContext.doCallWithMetrics(FunctionCallDelegate.java:362) at com.appiancorp.core.expr.FunctionCallDelegate$ExternalFunctionCallWithContext.eval(FunctionCallDelegate.java:333)
Works fine for me on 23.3 and the latest version of the plugin (which dates back to 2016 :))
Can you give more details on how you are calling it?
Hi Mathieu, thanks for your reply.
i am storing the date and time for starttime in the database. after that i am pulling it from the db and passing it to the function
calworkminutesplugin(cdt.starttime, ri!endTime).
i tried even by adding gmt function as below:
calworkminutesplugin(gmt(cdt.starttime,"GMT+00:00"), ri!endTime).
both cases its failing. its fine in expression rule for both approaches. but when i call it from PM throwing an error message
How about putting both values you are passing in PVs first to see what you are passing to the expression?
Also - can you clarify the rule inputs for your expression? You have ri!endTime but what is cdt.starttime?
i am passing that as
i am passing rule inputs as
cdt - which holds the starttime(date and time) and other attributes
endtime - capturing it in pv in the process model as now() as soon as the task is completed and passing the same.
the approach:
created separate subprocess calling 2 times in main PM. before and after starting the task
sample code:
a!localVariables( if( a!isNullOrEmpty(ri!cdt.xx), { a!entityData( entity: entity constant, data: a!update( data: ri!cdt, index: { "filed one","filed two",....
}, value: {"value1"."value2"), } ),
).data }, { *****here i am caluculating the time taking ***** a!localVariables(
some filed calculation.....
i want get the total work min between 2 dates
local!totalmin : calworkminutesplugin(ri!cdt.starttime, ri!endTime)*/ a!entityData(entity: entity constant,data: a!update(data: ri!cdt,index: {"filed one","filed one",....
},value: {"calculated value1"."calculated value2",...,}),
).data
)
} ),
hopefully this will help.
The code is not super clear to me. For instance, why are you doing .data on a!entityData?
What I can say though is that the plugin seems to work fine when called from a process model therefore I would assume that there is something wrong with your expression.
Let me try to elaborate .
i am calling the same expression twice from PM
before starting the task, calling sub-process from main PM, that internal calling this expression, check the record exists or not so this time there is no record id so, it will return empty record id and dump the cdt data in DB like recordis, startdate etc
after the task completed, again calling the same sub-process from main PM that internal calling the same expression, it will check the record id is there or not and it will go to else part and calculating the time taken in min and updating the existing record.
hope this will help
i can able to resolve that PM error but the plug is not working as expected always returning 0.
i tried by passing the parameter like this
1.calworkminutesplugin( datetime(2023,09,15,5,15), datetime(2023,09,15,5,25))
returning 0 instead of 10 min
2.
gave the rule inputs as date and time the value i assigned as below
startdate in the expression editor of rule input i mentioned as "9/15/2023 5:15 AM"
startdate in the expression editor of rule input i mentioned as "9/15/2023 5:25 AM"
calworkminutesplugin(ri!startdate,ri!enddate)
this is also returning 0 instead of 10 min.
Any suggestion
Hi Rama,
Please check the process calendar setting of your environment , 0 might come in case of another time zone configured.
Thanks
I am not using any timezone and as well as calendar.
I might have to disappoint you. This function works with a process calendar which by default has a working time between 9am and 5pm. Both of the timestamps you are outside of that working time.
Now, the big question, do you need to respect working time?
no. I want to calculate network min based on the date and time.
this function is not working if pass calendar
any other suggestion
In the plugin "Date and Time Utilities" there is a function elapsedminutes().
true but it will not consider the network hours and calendar. i want calculate only lapsed network min
It's either calworkminutesplugin() for net work minutes or elapsedminutes() for total minutes.
All the net work stuff in Appian is based on the Process Calendar.
Sure. But this plug-in is not working correctly if add calendar. without calendar its working.
It's taking the default system calendar.
calworkminutesplugin(): This returns the actual number of work minutes between two given Datetimes (both inclusive), according to the calendar defined for the system.
That's pretty simple. Any time outside the working time is considered zero. So
calworkminutesplugin(datetime(2023,09,15,5,15),datetime(2023,09,15,5,25))
returning 0
is the expected behaviour.
i tried with deferent calendar but its not working. works fine for without calendar
As mentioned earlier, Please check the working time defined in the calendar that is being passed in the function, it will take the default working hours if no custom calendar is passed. You can make your own calendar and define working hours for that as well and use that. As Stefan said , this is expected behavior. These functions basically work according to process calendar settings defined. Hope that helps
Unknown said:calworkminutesplugin(datetime(2023,09,15,5,15),datetime(2023,09,15,5,25)) returning 0 is the expected behaviour.
This is really running in circles ...
What calendars do you use and how are they configured?
What does "its not working" actually mean?