Error message help

Right so all my scripts are working as expected when tested from scripts section in manage but something is causing an error but not sure why if they work fine when tested…
This is the error message;

[General Info]

Application: SambaPOS
Version:     5.1.57
Region:      en
DB:          SQ
Machine:     JTR-PC
User:        JTR
Date:        2016-01-12
Time:        10:15

User Explanation:

JTR 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.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at Samba.Presentation.App.Main()

Inner Exception 1
Type:        Microsoft.ClearScript.ScriptEngineException
Message:     Syntax error
Source:      ClearScript
Stack Trace: at Microsoft.ClearScript.ScriptEngine.ThrowScriptError(IScriptEngineException scriptError)
   at Microsoft.ClearScript.Windows.WindowsScriptEngine.ThrowScriptError(Exception exception)
   at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass51_0`1.<ScriptInvoke>b__0()
   at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func)
   at Microsoft.ClearScript.Windows.WindowsScriptEngine.ScriptInvoke[T](Func`1 func)
   at Microsoft.ClearScript.Windows.WindowsScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard)
   at Samba.Services.Implementations.ExpressionModule.ExpressionEngine.Invoke(String expression, String function, Object dataObject, Object[] args)
   at Samba.Services.Implementations.ExpressionModule.ExpressionService.InvokeScript(String handlerFunction, Object dataObject)
   at Samba.Modules.AutomationModule.ActionProcessors.ExecuteScript.Process(ActionData actionData)
   at Samba.Services.Common.RuleActionTypeRegistry.ProcessAction(String actionType, ActionData actionData)
   at Samba.Services.Implementations.AutomationModule.AutomationService.ProcessAction(String actionType, ActionData actionData)
   at Samba.Modules.AutomationModule.AutomationModule.<OnInitialization>b__5_0(EventParameters`1 x)
   at Microsoft.Practices.Prism.Events.EventSubscription`1.InvokeAction(Action`1 action, TPayload argument)
   at Microsoft.Practices.Prism.Events.EventSubscription`1.<>c__DisplayClass2.<GetExecutionStrategy>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=
DevExpress.Xpf.LayoutControl.v14.1, Version=
System.Xml, Version=
DevExpress.Xpf.Grid.v14.1, Version=
System, Version=
DevExpress.Xpf.Grid.v14.1.Core, Version=
WindowsBase, Version=
System.Xaml, Version=
Samba.Domain, Version=
System.Core, Version=
PresentationFramework, Version=
Samba.Infrastructure, Version=
Microsoft.Practices.Prism, Version=
System.Runtime.Serialization, Version=
Microsoft.Practices.Prism.MefExtensions, Version=
System.ComponentModel.Composition, Version=
PresentationCore, Version=
DevExpress.Xpf.Core.v14.1, Version=
Samba.Services, Version=
Samba.Presentation.Services, Version=
System.Windows.Forms, Version=
System.Drawing, Version=
Stateless, Version=
Samba.Persistance, Version=
PropertyTools, Version=2012.4.14.1
Samba.Localization, Version=
ReachFramework, Version=
Samba.Infrastructure.Data, Version=
EntityFramework, Version=
FluentValidation, Version=
Omu.ValueInjecter, Version=
Microsoft.Practices.ServiceLocation, Version=
Microsoft.CSharp, Version=


[System Info]

Operating System
-Microsoft Windows 7 Professional
--CodeSet = 1252
--CSDVersion = Service Pack 1
--CurrentTimeZone = 0
--FreePhysicalMemory = 1018828
--OSArchitecture = 64-bit
--OSLanguage = 1033
--ServicePackMajorVersion = 1
--ServicePackMinorVersion = 0
--Version = 6.1.7601

--Manufacturer = Gigabyte Technology Co., Ltd.
--Model = To be filled by O.E.M.
--TotalPhysicalMemory = 8551956480
--UserName = JTR-PC\JTR


Only bit I recognize is the tipical script error of Exception has been thrown by the target of an invocation. but not sure why since they work fine in testing…

Probably missing a quote, bracket, brace, end-line or something of that sort.

1 Like

But the script run fine when tested within scripts section… :frowning:

Maybe it runs fine in testing with test-data. But it might be that live data is introducing characters that need to be escaped, such as single/double quotes or slashes, or… ? In particular, I would look at the data for State Date, since it contains escaped slashes, etc. You might need to double-escape.

Time to throw some debugging in there with Show Message, or with JS Alert("varName:"+varName);

1 Like

Implemented both triggers this morning for the script flows at the same time so starting with disabling one.
See what happens.

What do you think to this one? :smile:

//Load NewBook Variables
var vars 								= script.Load("NewBookVariables","initialize");																			//--Load NewBook Variables

//Load Scripts
var NewBookTransferRequest				= script.Load("NewBookTransferRequest","generateRequest");																		//--Load Scripts
var programSettings						= script.Load("programSettings","getValue","updateValue");																//--Load dbTools Scripts
var dbTools		 						= script.Load("dbTools","ticketOrderCount","ticketOrderList","orderDetails","uniqueListofTags","salesTicketIdCount","salesTicketIdList","salesPaymentTotals","ticketPaymentsCount","ticketPaymentsList","paymentDetails","ticketDetails");	//--Load dbTools Scripts
var successTools 						= script.Load("NewBookTransferSuccess","setTicketChargesTag","setTicketTransferedState")

function transferData() {
	//--Define rundate and add lookup delay
	var runDateNow													= new Date();																//--set script run time
	var runDateValue												= runDateNow.valueOf();
	var transferLookupDateDelay										= salePostLookupDateDelay*60*1000;
	var calculatedEndDate											= runDateValue-transferLookupDateDelay;
	var endDate														= new Date(calculatedEndDate);
	var endDateValue												= endDate.valueOf();
	//--End date breakdown
	var endDateYear													= endDate.getYear();
	var endDateMonth												= endDate.getMonth()+1;
	var endDateDay													= endDate.getDate(); 
	var endDateHours												= endDate.getHours();
	var endDateMinutes												= endDate.getMinutes();
	var endDateSeconds												= endDate.getSeconds();
	//--End date formatting
	var endDateFormatted											= endDateYear+'-'+endDateMonth+'-'+endDateDay+' ';
	endDateFormatted												+= endDateHours+':'+endDateMinutes+':'+endDateSeconds;
	//--Interval difference calculations and minimum interval if less than 15 mins 
	var intervalDifferenceHours										= salePostIntervalHours*60*60*1000;
	var intervalDifferenceMinutes									= salePostIntervalMinutes*60*1000;
	var intervalDifferenceTotalSum									= intervalDifferenceHours+intervalDifferenceMinutes;
	var intervalDiferenceMinimumMin									= 15;																									//--minimum interval difference in minutes
	var intervalDiferenceMinimum									= intervalDiferenceMinimumMin*60*1000;
	if (intervalDifferenceTotalSum < intervalDiferenceMinimum)
		var intervalDifferenceTotal									= intervalDiferenceMinimum;
		} else {
		var intervalDifferenceTotal									= intervalDifferenceTotalSum;
	//--Define script run lookup start date.
	var runStartDateCalculation										= endDateValue-intervalDifferenceTotal;
	var runStartDate	 											= new Date(runStartDateCalculation);
	var runStartDateValue											= runStartDate.valueOf();
	//--Lookup last transfer endDate
	var lastTransferEndDateSetting									= programSettings.getValue('lastTransferEndDate');
	var lastTransferEndDateValue									= Number(lastTransferEndDateSetting);
	var lastTransferEndDate											= new Date(lastTransferEndDateValue);
	//--Set and format last transfer date time as startDate
	var startDateYear												= lastTransferEndDate.getYear();
	var startDateMonth												= lastTransferEndDate.getMonth()+1;
	var startDateDay												= lastTransferEndDate.getDate(); 
	var startDateHours												= lastTransferEndDate.getHours();
	var startDateMinutes											= lastTransferEndDate.getMinutes();
	var startDateSeconds											= lastTransferEndDate.getSeconds();
	var startDateFormatted											= startDateYear+'-'+startDateMonth+'-'+startDateDay+' ';
	startDateFormatted												+= startDateHours+':'+startDateMinutes+':'+startDateSeconds;

	//--Set runTranser yes if last rune date time is before runStartDate
	if (runStartDateValue > lastTransferEndDateValue)
		var runTransfer = 'yes';
		} else {
		var runTransfer = 'no';
	var newTickets													= salesTicketIdCount(startDateFormatted,endDateFormatted);
	if (newTickets > 0)
		if (runTransfer == 'yes')
			var chargeResponse										= NewBookTransferRequest.generateRequest(startDateFormatted,endDateFormatted);
			var responseJsonParse									= JSON.parse(chargeResponse);
			var successMessage										= responseJsonParse.success;
			var successData											=;
			if (successMessage == 'true')
				var updatedEndDate									= endDateValue+'';
				var successTicketIdsList							= salesTicketIdList(startDateFormatted,endDateFormatted);
				var successTicketIdsCount							= salesTicketIdCount(startDateFormatted,endDateFormatted);
				for (t = 0; t < successTicketIdsCount ; t++)
					var loopChargeTags								= '';
					var loopTicketId								= successTicketIdsList[t];
					if (successData[t].charge_ids) {successTools.setTicketChargesTag(loopTicketId,'Charge IDs: '+successData[t].charge_ids);}
					if (successData[t].credit_ids) {successTools.setTicketChargesTag(loopTicketId,'Credit IDs: '+successData[t].credit_ids);}
					if (successData[t].payment_ids) {successTools.setTicketChargesTag(loopTicketId,'Payment IDs: '+successData[t].payment_ids);}
					if (successData[t].refund_ids) {successTools.setTicketChargesTag(loopTicketId,'Refund IDs: '+successData[t].refund_ids);}
				} else {
				//--post run but fail log, internet check & email
			var response = runTransfer;
		} else {
		var response = 'No New Tickets';
	return response+' '+newTickets+' '+startDateFormatted+' '+endDateFormatted+' '+chargeResponse
1 Like

You do realize that if you keep this up, it will be you that everyone comes to asking for help and advice on scripts, right? :wink:


TBH, if we had more api helpers I would probably script the whole thing LOL.

Am really getting into the swing of it as getting to the point I can write decent sections without having to run test on each step…
Quite proud of myself for less than 3 months since even looked at JScript or SQL.
Although most of that is thats to the helping hands from you in the beginning when getting it straight in my head.

Defiantly need some order & ticket creation apis :smile:


I would be very interested in creating integration’s with a variety of sites both restaurant and retail.
Also given the time taken to implement would have to work out a way to charge for them.
Not sure if that was a possible direction via configuration tasks or a form of user submitted samba market type thing like with modules and templates for Wordpress etc.

Was hoping for a little clarification on triggers…

From what I’ve seen on the forum triggers will only fire if a ticket is not open, but how does this work with a multi terminal system?
If setup with rule mapped on server only which will be headless machine, will tickets on other machines prevent it from firing?

Triggers are not local correct? So presumably I should map the rule to a specific terminal for my purpose of firing sync scripts.

What are you calling sync scripts? What do you mean headless? Triggers will run on all terminals if a ticket is open on terminal a it will not execute trigger on terminal a only the others continue to work. Trigger will fire soon as ticket is closed on terminal a.

Headless as in server with no monitor, not used as terminal.

Sync scripts being my PMS scripts to sync room/book/guest info into samba and transfer sales data to PMS system.
Syncs data into entity fields so only needed to run on one machine.

So yes you should just map the trigger rules to the terminal that won’t run open tickets.

1 Like

Hmmmmm, the issue seems to be if both scripts are run at the same time…
They are on separate triggers and separate rules.
Hazarding a guess that they are both calling a ‘sub script’ at the same time…

OK, think I have the solution with staggering the triggers;

Have ticket transfer script triggered every 5 minutes, it has a built in timer which has an interval variable set to minimum 15 mins and also remembers last time it ran.
I did this so that if the internet was down and a due transfer fails it will keep trying every 5 minutes to catch up and as it remembers last time run even if internet went down for hours it would still post the tickets once back online.

The room data script will just be a regular update.

Now having better understanding of corn expressions I might set the hours for both to say 0,1,2,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 so that it doesn’t bother trying to transfer through the night while closed.

FYI for anyone working with triggers, be sure to logout/restart samba after making changes, oddly at one point although only having 2 triggers firing 2 rules the message action AND the script seem to be firing 2-3 times for each…
Restart samba solved but not sure of cause but guessed it was the combination of multiple triggers, message and scripts whilst changing trigger settings. Either way…