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) {
debugger
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+‘’;
dlg.ShowMessage(retValue);
return retValue.toString();
}
catch (err) {
dlg.ShowMessage(‘Error!!’);
return ‘Error’;
}

}

This is the showMessage before the return:

image

after closing the message it throws the error

The exception is:


[General Info]

Application: SambaPOS
Version: 5.5.0
Region: en
DB: SQ
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=4.0.0.0
System, Version=4.0.0.0
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=4.0.0.0
Samba.Presentation.Services, Version=5.5.8206.19290
System.Core, Version=4.0.0.0
PresentationCore, Version=4.0.0.0
WindowsBase, Version=4.0.0.0
PresentationFramework, Version=4.0.0.0
DevExpress.Xpf.LayoutControl.v17.2, Version=17.2.13.0
System.Xml, Version=4.0.0.0
DevExpress.Xpf.Grid.v17.2, Version=17.2.13.0
DevExpress.Xpf.Grid.v17.2.Core, Version=17.2.13.0
System.Xaml, Version=4.0.0.0
Samba.Infrastructure, Version=5.5.8206.19282
Microsoft.Practices.Prism, Version=4.0.0.0
System.Runtime.Serialization, Version=4.0.0.0
Microsoft.Practices.Prism.MefExtensions, Version=4.0.0.0
DevExpress.Xpf.Core.v17.2, Version=17.2.13.0
System.Windows.Forms, Version=4.0.0.0
System.Drawing, Version=4.0.0.0
Samba.Persistance, Version=5.5.8206.19286
Stateless, Version=1.0.0.0
PropertyTools, Version=2012.4.14.1
Samba.Localization, Version=5.3.8206.19283
ReachFramework, Version=4.0.0.0
EntityFramework, Version=6.0.0.0
FluentValidation, Version=3.4.0.0
NCalc, Version=1.3.8.0
Microsoft.CSharp, Version=4.0.0.0
Omu.ValueInjecter, Version=2.3.0.0
Microsoft.Practices.ServiceLocation, Version=1.0.0.0
DevExpress.Data.v17.2, Version=17.2.13.0
WindowsInput, Version=1.0.4.0


[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

Machine
-ABR-DESK
–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) {
    //debugger
    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());

        dlg.ShowMessage(exceptionMessage);

        return exceptionMessage;
    }
}