1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
| //-----------------------------------------------------------------------------
// JScript Example
// Created by: Josh Geving - Solutions Group
//
// Description: When entering a new vendor a button is provided to
// query the system to determine if the tax-id entered
// is unique, if not unique the vendor(s) with the matching
// tax-id id are displayed
//
// Last Tested on Smart Office Version 10.0.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
import System.Collections;
import System.Collections.Generic;
import System.Windows.Data;
import Mango.UI;
import Mango.UI.Core;
import Mango.UI.Services;
package S3.Client.Forms.JScript {
class JjgAP10CheckTaxID
{
var console, form, formGrid, button;
public function Init(element: Object, args: Object, controller : Object, debug : Object)
{
try {
form = controller;
formGrid = form.FormGrid;
console = debug;
console.WriteLine("Script initializing...");
if (element != null)
console.WriteLine("Connected element: " + element.Name);
// Add a button to the form
AddButton();
// Events
form.add_BeforeTransaction(OnBeforeTransaction);
form.add_BeforeUnload(OnBeforeUnload);
console.WriteLine("Script initialized.");
} catch (e) {
console.WriteLine(FormatException("Init", null, e));
}
}
// event handlers
public function OnBeforeTransaction(sender: Object, e: CancelTransactionEventArgs)
{
// test for good transaction
if (e.TransactionError)
return;
// no action on delete
if (e.FunctionCode == "D")
return;
// Don't allow add transaction if there is a match on ADD
if (e.FunctionCode == "A")
{
try {
// Field values
var taxid = form.GetElementValue("VEN-TAX-ID");
var vVendor = form.GetElementValue("VEN-VENDOR");
// no action if the user has not entered a value
if (taxid.length > 0)
{
// build up the Data Service call
var sProd = form.GetUserAttribute("productline");
var sFile = "APVENMAST";
var sField = "TAX-ID;VENDOR;VENDOR-GROUP";
var sIndex = "";
var sCond = "";
var sSelect = "TAX-ID=" + taxid + "%26VENDOR-STATUS^%3DA";
var sMax = "";
// Pass the variables for the API to DataService_Execute
var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax);
console.WriteLine("aDataAPI.length: " + aDataAPI.length);
// Did we get anything back from the call?
if(aDataAPI.length > 0)
{
var vendorList = "\n";
var vendorVal = "";
var i;
for(i = 0; i < aDataAPI.length; i++)
{
console.WriteLine(aDataAPI[i]);
// Build a list of vendors
vendorList += aDataAPI[i] + "\n";
}
var message = "Tax ID supplied matches vendor(s): " + vendorList + ". Transaction stopped.";
ConfirmDialog.ShowWarningDialog("Matching Vendor(s)", message, null);
form.SetMessage(message);
e.Cancel = true;
}
else{
console.WriteLine("***No Records***");
}
}
else
{
form.SetMessage("Tax ID not verified while blank");
}
} catch (ex) {
console.WriteLine(FormatException("OnBeforeTransaction", null, ex));
}
}
}
public function OnBeforeUnload(sender: Object, e: FormEventArgs)
{
// perform cleanup
form.remove_BeforeTransaction(OnBeforeTransaction);
form.remove_BeforeUnload(OnBeforeUnload);
button.remove_Click(OnButtonClick);
}
public function OnButtonClick(sender: Object, e: RoutedEventArgs)
{
try {
// Field values
var taxid = form.GetElementValue("VEN-TAX-ID");
var vVendor = form.GetElementValue("VEN-VENDOR");
// no action if the user has not entered a value
if (taxid.length > 0)
{
// build up the Data Service call
var sProd = form.GetUserAttribute("productline");
var sFile = "APVENMAST";
var sField = "TAX-ID;VENDOR;VENDOR-GROUP";
var sIndex = "";
var sCond = "";
var sSelect = "TAX-ID=" + taxid + "%26VENDOR-STATUS^%3DA%26VENDOR!=" + vVendor;
var sMax = "";
// Pass the variables for the API to DataService_Execute
var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax);
console.WriteLine("aDataAPI.length: " + aDataAPI.length);
// Did we get anything back from the call?
if(aDataAPI.length > 0)
{
var vendorList = "\n";
var vendorVal = "";
var i;
for(i = 0; i < aDataAPI.length; i++)
{
console.WriteLine(aDataAPI[i]);
// Build a list of vendors
vendorList += aDataAPI[i] + "\n";
}
var message = "Tax ID supplied matches vendor(s): " + vendorList;
ConfirmDialog.ShowWarningDialog("Matching Vendor(s)", message, null);
}
else
{
ConfirmDialog.ShowSuccessDialog("Tax ID Verified as Unique", "No matching Tax ID's found", null);
}
}
else
{
form.SetMessage("Tax ID not verified while blank");
}
} catch (ex) {
console.WriteLine(FormatException("OnButtonClick", null, ex));
}
}
/**
* DataService_Execute - This method returns an array for the api specified
* Detail description
* This method returns an array of values for for the api details
* @param required sProd, PROD, defaults to user profile if not set - required
* @param required sFile, FILE
* @param required sField, FIELD
* @param optional sIndex, INDEX, removed from api if not set
* @param optional sCond, COND
* @param optional sSelect, SELECT
* @param optional sMax, MAX, defaults to 0 if not set
* @access private
* @return array
*
* Example:
*
*
private function RunDataMine()
{
// build up the Data Service call
var sProd = form.GetUserAttribute("productline");
var sFile = "CUCODES";
var sField = "CURRENCY-CODE;DESCRIPTION";
var sIndex = "CUCSET1";
var sCond = "";
var sSelect = "";
var sMax = "";
// Pass the variables for the API to DataService_Execute
var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax);
console.WriteLine("aDataAPI.length: " + aDataAPI.length);
// Did we get anything back from the call?
if(aDataAPI.length > 0)
{
var i = 0;
for(i = 0; i < aDataAPI.length; i++)
{
console.WriteLine(aDataAPI[i]);
}
}
else{
console.WriteLine("***No Records***");
}
}
*/
private function DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax)
{
var a = new Array();
var aFields = new Array();
var i = 0;
var s = "";
var oXML;
var oRecs;
var oRecNum;
var oRec;
var oFields;
// Productline sProd empty, set from profile
if(sProd == ""){sProd = form.GetUserAttribute("productline");}
// Max sMax empty, set to 0 for all
if(sMax == ""){sMax = 0;}
// Build the complete Data Service Call
s = ScriptConstants.DataMinePath + "?PROD=" + sProd + "&FILE=" + sFile + "&FIELD=" + sField;
// If Index we add Index to the call
if(sIndex != ""){s += "&INDEX=" + sIndex;}
// The rest of the call
s += "&COND=" + sCond + "&SELECT=" + sSelect + "&MAX=" + sMax +
"&OUT=XML&DELIM="+ new Date().getTime(); // Time used to prevent caching
console.WriteLine("s: " + s);
// Make the server request, record the time it took
var bTime = new Date().getTime();
oXML = ScriptUtil.ServerRequest(s);
var eTime = new Date().getTime();
console.WriteLine("API Execution Time: " + (eTime-bTime)/1000 + "seconds");
// Get the Record Count Node
oRecs = oXML.SelectSingleNode("//RECORDS");
oRecNum = oRecs != null ? oRecs.ChildNodes.Count : 0;
console.WriteLine("oRecNum: " +oRecNum);
// Determine if records were returned
if(oRecNum == 0)
{
console.WriteLine("Data Service Call\n\n" + s + "\n\n returned " + oRecNum + " records.");
return a;
}
// Build an array with the results
for(oRec in oRecs.ChildNodes)
{
oFields = oRec.SelectSingleNode("./COLS");
aFields = new Array();
for(i = 0; i < oFields.ChildNodes.Count; i++)
{
aFields[aFields.length] = oFields.ChildNodes[i].InnerText;
}
a[a.length] = aFields;
}
return a;
}
// private functions
private function AddButton()
{
button = new Button();
button.Name = "TaxButton";
button.Content = "Verify Tax ID";
button.ToolTip = "Verify Tax ID Unique";
button.IsEnabled = true;
var size = 14;
button.Width = (ScriptConstants.DefaultColumnWidth * size);
button.add_Click(OnButtonClick);
Grid.SetColumn(button, 5);
Grid.SetRow(button, 2);
Grid.SetColumnSpan(button, size);
Grid.SetRowSpan(button, 1);
form.AddCustomElement(form.GetTabPageContainer("TF0-0"), button);
}
private function FormatException(funcName, prefMsg, e)
{
var errMsg = (typeof(prefMsg)=="string" ? prefMsg+"\n" : "Exception encountered:\n");
errMsg += " Class:\t\tJjgAP10CheckTaxID\n";
errMsg += " Function:\t"+funcName+"\n";
errMsg += " Name:\t\t" + e.name + "\n"
errMsg += " Number:\t" + (e.number & 0xFFFF) + "\n"
errMsg += " Message:\t" + e.message + "\n"
errMsg += " Description:\t" + e.description + "\n"
return errMsg;
}
} } |