Help with Script - MS Word

Hi I am doing some testing with Scripts. I have a Script which opens a Word Document.

function OpenWord(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var objEditor = new ActiveXObject("Word.Application");
objEditor.Visible = true; 
var doc = objEditor.Documents.Add ();
    var sel = objEditor.Selection;
    sel.TypeText("This is Text inputed to word");


I want to send Customer details like Name, Address, Email, Phone etc. to the word document. This is my first attempt at Scripts. Would I need create another script to get the customer information from Sambapos and then call that script from the above script.

I know there is probably easier ways to do this but I want to learn about scripts. Could someone give an example of how I would pass customer details to the script. When I run the above script Word opens and has the Text “This is Text inputed to word”

You will need to look at the SambaPOS JScript API helpers for api.Entity()

… like these:


1 Like

Hi I tried below but I am getting.

api.Entity(Test Customer).Data(Email).Get();

The best overloaded method match for 'Samba.Services.Implementations.ExpressionModule.Accessors.ApiService.ApiServiceAccessor.Entity(string)' has some invalid arguments

I was reading @JTRTech Update rooms Scritpt and he was doing it like below but I get Customers is undefined.

api.Entity(Customers).Data(Test Customer).Get(Email);

'Customers' is undefined

Put the values in quotes so they are strings, or define varables to contain the strings and use the variables:

api.Entity('Test Customer').Data('Email').Get();

If you don’t do that, then it is a literal, a variable, in which case it would be undefined, since you have not defined the content of the variable named Customers, Email, etc. And Test Customer cannot be used as a variable name, since it has a space in it.

I hope you can grasp that concept, if not, you are in over your head and won’t get far.

var entityType = 'Customers';
var entityName = 'Test Customer';
var customFieldName = 'Email';

1 Like

I understand what you are doing here and have it working on the Script page when I test. What I do not understand is -
I have a customer ticket open. I have a button called export. How do I get the selected customer from a ticket when I press export. Can I pass the selected customer details to the script?

You need to feed them into the script on the call.

{CALL:scriptName.functionName('{ENTITY NAME:Customer}','{TICKET NUMBER}')}

Would feed customer name and ticket number in to the script in the input variables.

So your function would then look something like this;

function functionName(customerName,ticketNumber) {
   return 'Name: '+customerName+' - Ticket Number: '+ticketNumber;

customerName and ticketNumber would then become variables inside the function with the value input when the function is called

so this;


would return

Name: Tom - Ticket Number: 1234