Help with Script

Every time I execute this script throws and error and quits the application, debugger does not start on time to debug the script:

function getUserStatus(userID) {
try {
var qry1 = “select StartState from EntityStateLogs where CustomData = '” + userID + “’ order by Id desc”;
var Status = sql.Query(qry1).First;
var Color = ‘White’;
if (Status === ‘PunchIn’){ Color = ‘White’; } else {Color = ‘Red’};
var retValue = ‘<size 50><color ’ + Color + ‘>Clock Status:
’ +’<size 40><color ’ + Color + ‘>’+Status+‘’;
return retValue.toString();
catch (err) {
return ‘Error’;


This is the showMessage before the return:


after closing the message it throws the error

The exception is:

[General Info]

Application: SambaPOS
Version: 5.5.0
Region: en
Machine: ABR-DESK
User: algis
Date: 7/6/2022
Time: 5:07 PM

User Explanation:

algis said “”

[Exception Info 1]

Top-level Exception
Type: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
Stack Trace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Inner Exception 1
Type: System.IndexOutOfRangeException
Message: Index was outside the bounds of the array.
Source: Samba.Services
Stack Trace: at Samba.Services.Implementations.ExpressionModule.ExpressionService.InvokeScript(String handlerFunction, Object dataObject)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at .Process(ActionData , RuleExecutionContext )
at Samba.Services.Common.RuleActionTypeRegistry.ProcessAction(String actionType, ActionData actionData, RuleExecutionContext context)
at Samba.Services.Implementations.AutomationModule.AutomationService.ProcessAction(String actionType, ActionData actionData, RuleExecutionContext context)
at Samba.Services.Implementations.AutomationModule.ActionDataBuilder.<>c__DisplayClass13_0.b__0()
at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
at System.Windows.Threading.Dispatcher.Invoke(Action callback)
at Samba.Services.Implementations.AutomationModule.ActionDataBuilder.InvokeWith(AppState appState, RuleExecutionContext context)
at Samba.Services.Implementations.AutomationModule.RuleExecutor.ExecuteWithoutLogging(Object ruleData)
at Samba.Services.Implementations.AutomationModule.RuleExecutor.ExecuteWith(Object dataParameter)
at Samba.Services.Implementations.AutomationModule.NotificationService.NotifyEvent(String eventName, Object dataParameter, AppState appState)
at CallSite.Target(Closure , CallSite , INotificationService , String , Object , AppState )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Samba.Services.Implementations.AutomationModule.CommandExecutionService.ExecuteAutomationCommand(AppState appState, String commandName, String commandValue, Object dataObject, Boolean background)
at f8p4qeu67t6na32. .(EventParameters1 ) at Microsoft.Practices.Prism.Events.EventSubscription1.InvokeAction(Action1 action, TPayload argument) at Microsoft.Practices.Prism.Events.EventSubscription1.<>c__DisplayClass2.b__0(Object[] arguments)
at Microsoft.Practices.Prism.Events.EventBase.InternalPublish(Object[] arguments)
at Microsoft.Practices.Prism.Events.CompositePresentationEvent`1.Publish(TPayload payload)
at Samba.Presentation.Services.Common.ExtensionMethods.Publish[TEventsubject](TEventsubject eventArgs, String eventTopic, Action expectedAction)

[Assembly Info]

mscorlib, Version=
System, Version=
Samba.Services, Version=5.5.8206.19287
Samba.Domain, Version=5.5.8206.19286
Samba.Infrastructure.Data, Version=5.5.8206.19285
System.ComponentModel.Composition, Version=
Samba.Presentation.Services, Version=5.5.8206.19290
System.Core, Version=
PresentationCore, Version=
WindowsBase, Version=
PresentationFramework, Version=
DevExpress.Xpf.LayoutControl.v17.2, Version=
System.Xml, Version=
DevExpress.Xpf.Grid.v17.2, Version=
DevExpress.Xpf.Grid.v17.2.Core, Version=
System.Xaml, Version=
Samba.Infrastructure, Version=5.5.8206.19282
Microsoft.Practices.Prism, Version=
System.Runtime.Serialization, Version=
Microsoft.Practices.Prism.MefExtensions, Version=
DevExpress.Xpf.Core.v17.2, Version=
System.Windows.Forms, Version=
System.Drawing, Version=
Samba.Persistance, Version=5.5.8206.19286
Stateless, Version=
PropertyTools, Version=2012.4.14.1
Samba.Localization, Version=5.3.8206.19283
ReachFramework, Version=
EntityFramework, Version=
FluentValidation, Version=
NCalc, Version=
Microsoft.CSharp, Version=
Omu.ValueInjecter, Version=
Microsoft.Practices.ServiceLocation, Version=
DevExpress.Data.v17.2, Version=
WindowsInput, Version=

[System Info]

Operating System
-Microsoft Windows 10 Pro
–CodeSet = 1252
–CSDVersion =
–CurrentTimeZone = -300
–FreePhysicalMemory = 7172844
–OSArchitecture = 64-bit
–OSLanguage = 1033
–ServicePackMajorVersion = 0
–ServicePackMinorVersion = 0
–Version = 10.0.19044

–Manufacturer = Dell Inc.
–Model = OptiPlex 9010
–TotalPhysicalMemory = 17060749312
–UserName = ABR-DESK\algis

I think some of the script got cut off because of formatting so you’ll probably need to edit it.

When I execute this I get no errors. I’ve also wrapped it in a try/catch block that will display any errors and you can uncomment lines 36 & 37 to write the exception info to a file.

function getUserStatus(userID) {
    var retValue;
    var hostException;

    var isSuccessful = host.tryCatch
            function () {
                var qry1 = "select StartState from EntityStateLogs where CustomData = '" + userID + "' order by Id desc";
                var Status = sql.Query(qry1).First;
                Status = 'PunchIn';
                var Color = 'White';

                if (Status === 'PunchIn') {
                    Color = 'White';
                    Status = 'Punch In';
                else {
                    Color = 'Red'
                    Status = 'Punch Out';

                retValue = '<size 50><color' + Color + '>Clock Status: </color></size>' + '<size 40><color ' + Color + '>' + Status + '</color></size>';
            function (exception) {
                hostException = exception;
                return true;

    if (isSuccessful) {
        return retValue;
    else {
        exceptionMessage = hostException.GetBaseException().ToString();

        // file.AppendToFile('c:/samba_exception.txt', exceptionMessage);
        // file.AppendToFile('c:/samba_exception.txt', hostException.ToString());


        return exceptionMessage;