UXDE dot Net Wordpress Themes

Posts Selected From the Category "Smart Office Scripting"

Display Vendor Balance in AP10 using Smart Office Scripting

in Smart Office, Smart Office Scripting / No Comments

The following example utilizes Smart Office scripting to hook into the AfterTransaction event to display the corresponding Vendor balance.  Not a very complicated script. Basically a new label added to the header of the form and a custom Data Query function to gather values from the form and fetch the balance, which is then sent to the new label.

ScriptAP10VendorBalance

 

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
//-----------------------------------------------------------------------------
//  JScript Example
//  Created by:     Josh Geving - Innovations Group
//  
//  Description:    Example script to fetch a vendor balance from APVENBAL
//
//  Notice:         VBASET2 is being used as the index which is Vendor Group
//                  and Vendor, depending on yous situation you may choose to
//                  change the code below and use VBASET1 which includes 
//                  Company
//                  
//
//  Last Tested on Smart Office Version 10.1.0.38
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
 
package S3.Client.Forms.JScript {
 
class JjgAp10Balance
{
    var console, form, formGrid;
 
    public function Init(element: Object, args: Object, controller: Object, debug: Object)
    {
        try {
            form = controller;
            formGrid = form.FormGrid;
            console = debug;
 
            // TODO Add your code here
 
            // add a lable to display the vendor balance
            var label = ControlsUtil.AddCustomLabel(form, formGrid, "lblBalance", 1, 60, 10, "");
 
            // hook into the AfterTransaction event
            form.add_AfterTransaction(OnAfterTransaction);
 
            form.add_BeforeUnload(OnBeforeUnload);
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
 
        // remove the hook for AfterTransaction
        form.remove_AfterTransaction(OnAfterTransaction);
 
        form.remove_BeforeUnload(OnBeforeUnload);
    }
 
    // AfterTransaction Event
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
        // variable for balance
        var vBalance = RunDataMine();
 
        // set the value of the custom label to the balance found
        form.SetCustomElementValue("lblBalance", vBalance);
 
    }
 
    private function RunDataMine()
    {
        //OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL;
 
        //gather form variables from the transaction
        var vVendorGroup    = form.GetTransactionValue("VEN-VENDOR-GROUP");
        var vVendor         = form.GetTransactionValue("VEN-VENDOR").Trim();
 
        // build up the Data Service call
        var sProd       = form.GetUserAttribute("productline");
        var sFile       = "APVENBAL";
        var sField      = "CURRENT-BAL";
        var sIndex      = "VBASET2&KEY="+vVendorGroup+"="+vVendor+"";
        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]);
                return aDataAPI[i];
            }
        }
        else{
            console.WriteLine("***No Records***");
            return "No Balance";
        }
    }
 
    // private functions
    /**
     * 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()
    {
        //OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL;
 
        //gather form variables from the transaction
        var vVendorGroup    = form.GetTransactionValue("VEN-VENDOR-GROUP");
        var vVendor         = form.GetTransactionValue("VEN-VENDOR").Trim();
 
        // build up the Data Service call
        var sProd       = form.GetUserAttribute("productline");
        var sFile       = "APVENBAL";
        var sField      = "CURRENT-BAL";
        var sIndex      = "VBASET2&KEY="+vVendorGroup+"="+vVendor+"";
        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]);
                return aDataAPI[i];
            }
        }
        else{
            console.WriteLine("***No Records***");
            return "No Balance";
        }
    }
 
    */
    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;
    }
 
} }
//-----------------------------------------------------------------------------
//	JScript Example
//	Created by: 	Josh Geving - Innovations Group
//	
//	Description: 	Example script to fetch a vendor balance from APVENBAL
//
//	Notice:			VBASET2 is being used as the index which is Vendor Group
//					and Vendor, depending on yous situation you may choose to
//					change the code below and use VBASET1 which includes 
//					Company
//					
//
//	Last Tested on Smart Office Version 10.1.0.38
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;

package S3.Client.Forms.JScript {

class JjgAp10Balance
{
	var console, form, formGrid;

	public function Init(element: Object, args: Object, controller: Object, debug: Object)
	{
		try {
			form = controller;
			formGrid = form.FormGrid;
			console = debug;

			// TODO Add your code here

			// add a lable to display the vendor balance
			var label = ControlsUtil.AddCustomLabel(form, formGrid, "lblBalance", 1, 60, 10, "");

			// hook into the AfterTransaction event
			form.add_AfterTransaction(OnAfterTransaction);

			form.add_BeforeUnload(OnBeforeUnload);

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup

		// remove the hook for AfterTransaction
		form.remove_AfterTransaction(OnAfterTransaction);

		form.remove_BeforeUnload(OnBeforeUnload);
	}

	// AfterTransaction Event
	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
		// variable for balance
		var vBalance = RunDataMine();

		// set the value of the custom label to the balance found
		form.SetCustomElementValue("lblBalance", vBalance);

	}

	private function RunDataMine()
	{
		//OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL;

		//gather form variables from the transaction
		var vVendorGroup 	= form.GetTransactionValue("VEN-VENDOR-GROUP");
		var vVendor 		= form.GetTransactionValue("VEN-VENDOR").Trim();

		// build up the Data Service call
		var sProd 		= form.GetUserAttribute("productline");
		var sFile 		= "APVENBAL";
		var sField		= "CURRENT-BAL";
		var sIndex 		= "VBASET2&KEY="+vVendorGroup+"="+vVendor+"";
		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]);
				return aDataAPI[i];
			}
		}
		else{
			console.WriteLine("***No Records***");
			return "No Balance";
		}
	}

	// private functions
	/**
	 * 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()
	{
		//OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL;

		//gather form variables from the transaction
		var vVendorGroup 	= form.GetTransactionValue("VEN-VENDOR-GROUP");
		var vVendor 		= form.GetTransactionValue("VEN-VENDOR").Trim();

		// build up the Data Service call
		var sProd 		= form.GetUserAttribute("productline");
		var sFile 		= "APVENBAL";
		var sField		= "CURRENT-BAL";
		var sIndex 		= "VBASET2&KEY="+vVendorGroup+"="+vVendor+"";
		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]);
				return aDataAPI[i];
			}
		}
		else{
			console.WriteLine("***No Records***");
			return "No Balance";
		}
	}

	*/
	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;
	}

} }

Using LSO Scripting to Access SQL Database Directly

in Smart Office, Smart Office Scripting / No Comments

Although it is not condoned, at least with regards to accessing S3 application data, sometimes it is required to access a SQL database directly. At least when you are accessing third party data that you want to integrate into an S3 form.  Here is an example of reading vendor names from the APVENMAST table directly from SQL.  I do not take credit for all of this code. Most of it was available online already in some form, I merely put it all together to work inside an LSO script. Be careful.

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
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
 
import System.Data; //imported for example
import System.Data.SqlClient; //imported for example
 
package S3.Client.Forms.JScript {
 
class JjgSql
{
    var console, form, formGrid;
 
    public function Init(element: Object, args: Object, controller: Object, debug: Object)
    {
        try {
            form = controller;
            formGrid = form.FormGrid;
            console = debug;
 
            // TODO Add your code here
 
            //begin sql example
            try {
                //connection string to database including server, database, userid and password
                var connectionString : String = "Integrated Security=False;database=apps;server=lsfserver;User ID=lawson;Password=Lawson1975;";
 
                //the sql query
                var commandText : String = "SELECT VENDOR_VNAME FROM apps.APVENMAST";
 
                //the connection
                var connection : SqlConnection = new SqlConnection(connectionString);
                var command : SqlCommand = new SqlCommand(commandText,connection);
                //command.CommandType = CommandType.StoredProcedure;  //if stored
                command.CommandTimeout = 60; //default = 30
 
                //set Stored Procedure Parameters if needed
                //command.Parameters.AddWithValue();
 
                //open a connection
                connection.Open();
 
                //set up the reader
                var reader : SqlDataReader;
                reader = command.ExecuteReader();
 
                //if successful read we loop over the response
                if (reader != null)
                {
                        var i : int = 0;
                        while (reader.Read())
                        {
                        i++;
 
                        // *********************************************************
                        // Access the record in the recordset returned and
                        // perform the operation required:
                        // *********************************************************
                        // Column values accessed like so:
                        // reader["ColumnName1"].ToString();  OR   reader[0].ToString();
 
                        //this will write out the first column 
                        //console.WriteLine(reader.GetString(0));  // this works too
                        console.WriteLine(reader["VENDOR_VNAME"].ToString());
                        }
                        reader.Close();
                }
                connection.Close();
            }
            catch (ex)
            {
                console.WriteLine(ScriptUtil.FormatException("Sql", ex));
            }
            //end sql example
 
            form.add_BeforeUnload(OnBeforeUnload);
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
        form.remove_BeforeUnload(OnBeforeUnload);
    }
 
    // private functions
 
} }
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;

import System.Data; //imported for example
import System.Data.SqlClient; //imported for example

package S3.Client.Forms.JScript {

class JjgSql
{
	var console, form, formGrid;

	public function Init(element: Object, args: Object, controller: Object, debug: Object)
	{
		try {
			form = controller;
			formGrid = form.FormGrid;
			console = debug;

			// TODO Add your code here

			//begin sql example
			try {
				//connection string to database including server, database, userid and password
				var connectionString : String = "Integrated Security=False;database=apps;server=lsfserver;User ID=lawson;Password=Lawson1975;";

				//the sql query
				var commandText : String = "SELECT VENDOR_VNAME FROM apps.APVENMAST";

				//the connection
				var connection : SqlConnection = new SqlConnection(connectionString);
				var command : SqlCommand = new SqlCommand(commandText,connection);
				//command.CommandType = CommandType.StoredProcedure;  //if stored
				command.CommandTimeout = 60; //default = 30

				//set Stored Procedure Parameters if needed
				//command.Parameters.AddWithValue();

				//open a connection
				connection.Open();

				//set up the reader
				var reader : SqlDataReader;
				reader = command.ExecuteReader();

				//if successful read we loop over the response
				if (reader != null)
				{
			    		var i : int = 0;
			    		while (reader.Read())
			    		{
						i++;

						// *********************************************************
						// Access the record in the recordset returned and
						// perform the operation required:
						// *********************************************************
						// Column values accessed like so:
						// reader["ColumnName1"].ToString();  OR   reader[0].ToString();

						//this will write out the first column 
						//console.WriteLine(reader.GetString(0));  // this works too
						console.WriteLine(reader["VENDOR_VNAME"].ToString());
			    		}
			    		reader.Close();
				}
				connection.Close();
			}
			catch (ex)
			{
				console.WriteLine(ScriptUtil.FormatException("Sql", ex));
			}
			//end sql example

			form.add_BeforeUnload(OnBeforeUnload);

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup
		form.remove_BeforeUnload(OnBeforeUnload);
	}

	// private functions

} }

PO30 Display the Line Unit Cost on Each Line – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

Display the Line Unit Cost in each line next to the item description.

 

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
//-----------------------------------------------------------------------------
//  JScript Example
//  Created by:     Josh Geving - Solutions Group
//
//  Description:    Display the Line Unit cost oin each line - PO30
//
//
//  Last Tested on Smart Office Version 10.0.1.5
//-----------------------------------------------------------------------------
 
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
 
package S3.Client.Forms.JScript {
 
class JjgPO30LineCost
{
    var console, form, formGrid;
 
    public function Init(element: Object, args: Object, controller: Object, debug: Object)
    {
        try {
            form = controller;
            formGrid = form.FormGrid;
            console = debug;
 
            // TODO Add your code here
            form.add_AfterTransaction(OnAfterTransaction);
 
            form.add_BeforeUnload(OnBeforeUnload);
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
        form.remove_AfterTransaction(OnAfterTransaction);
        form.remove_BeforeUnload(OnBeforeUnload);
    }
 
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
        // test for good transaction
        if (e.TransactionError)
            return;
 
        // no action on delete
        if (e.FunctionCode == "D")
            return;
 
        // Loop through the lines
        var row             = 0;
        var vCompany        = form.GetTransactionValue("POR-COMPANY");
        var vPurchaseOrder  = form.GetTransactionValue("POR-PO-NUMBER").Trim();
        var vRelease        = form.GetTransactionValue("POR-PO-RELEASE");
        var vPOCode         = form.GetTransactionValue("POR-PO-CODE");
 
        for(row = 0; row <= 4; row++)
        {
            var vItem = form.GetTransactionValue("ITEM-DETAILr" + row);
            var vLine = form.GetTransactionValue("PRL-PO-LINE-NBRr" + row);
 
            // build up the Data Service call
            var sProd       = form.GetUserAttribute("productline");
            var sFile       = "POLINE";
            var sField      = "ENT-UNIT-CST";
            var sIndex      = "PLISET1&KEY=" + vCompany + "=" + vPurchaseOrder + "=" + vRelease + "=" + vPOCode + "=" + vLine;
            var sCond       = "";
            var sSelect     = "";
            var sMax        = "";
 
            // Pass the variables for the API to DataService_Execute
            if(vItem != "")
            {
                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]);
                        form.SetTransactionValue("ITEM-DETAILr" + row, vItem + " - Unit Cost: " + aDataAPI[i]);
                    }
                }
                else{
                    console.WriteLine("***No Records***");
                }
            }
        }       
 
    }
 
    // private functions
 
    /**
     * 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
    */
    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;
    }
 
} }
//-----------------------------------------------------------------------------
//	JScript Example
//	Created by: 	Josh Geving - Solutions Group
//
//	Description: 	Display the Line Unit cost oin each line - PO30
//
//
//	Last Tested on Smart Office Version 10.0.1.5
//-----------------------------------------------------------------------------

import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;

package S3.Client.Forms.JScript {

class JjgPO30LineCost
{
	var console, form, formGrid;

	public function Init(element: Object, args: Object, controller: Object, debug: Object)
	{
		try {
			form = controller;
			formGrid = form.FormGrid;
			console = debug;

			// TODO Add your code here
			form.add_AfterTransaction(OnAfterTransaction);

			form.add_BeforeUnload(OnBeforeUnload);

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup
		form.remove_AfterTransaction(OnAfterTransaction);
		form.remove_BeforeUnload(OnBeforeUnload);
	}

	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
		// test for good transaction
		if (e.TransactionError)
			return;

		// no action on delete
		if (e.FunctionCode == "D")
			return;

		// Loop through the lines
		var row				= 0;
		var vCompany		= form.GetTransactionValue("POR-COMPANY");
		var vPurchaseOrder	= form.GetTransactionValue("POR-PO-NUMBER").Trim();
		var vRelease		= form.GetTransactionValue("POR-PO-RELEASE");
		var vPOCode			= form.GetTransactionValue("POR-PO-CODE");

		for(row = 0; row <= 4; row++)
		{
			var vItem = form.GetTransactionValue("ITEM-DETAILr" + row);
			var vLine = form.GetTransactionValue("PRL-PO-LINE-NBRr" + row);

			// build up the Data Service call
			var sProd 		= form.GetUserAttribute("productline");
			var sFile 		= "POLINE";
			var sField		= "ENT-UNIT-CST";
			var sIndex 		= "PLISET1&KEY=" + vCompany + "=" + vPurchaseOrder + "=" + vRelease + "=" + vPOCode + "=" + vLine;
			var sCond 		= "";
			var sSelect		= "";
			var sMax 		= "";

			// Pass the variables for the API to DataService_Execute
			if(vItem != "")
			{
				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]);
						form.SetTransactionValue("ITEM-DETAILr" + row, vItem + " - Unit Cost: " + aDataAPI[i]);
					}
				}
				else{
					console.WriteLine("***No Records***");
				}
			}
		}		

	}

	// private functions

	/**
	 * 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
	*/
	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;
	}

} }

 

PO20 Display Vendor Record Fields within Header – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

Gather additional fields from the vendor record and dipslay them in the header as new labels.

 

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
//-----------------------------------------------------------------------------
//  JScript Example
//  Created by:     Josh Geving - Solutions Group
//
//  Description:    PO20 - Gather additional fields from the vendor record and
//                  dipslay them in the header as new labels
//
//  Optional:       form.GetUserAttribute("vendor_group");
//
//  Last Tested on Smart Office Version 10.0.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
 
// New import to support StyleManager
import Mango.UI.Core;
 
package S3.Client.Forms.JScript {
 
class JjgPO20VendorInfo
{
    var console, form, formGrid;
 
    public function Init(element: Object, args: Object, controller: Object, debug: Object)
    {
        try {
            form = controller;
            formGrid = form.FormGrid;
            console = debug;
 
            // TODO Add your code here
 
            // Add additional fields
            AddFields();
 
            // Capture AfterTransaction
            form.add_AfterTransaction(OnAfterTransaction);
 
            // Support user leaving Vendor Field
            form.GetElement("PCR-VENDOR").add_LostFocus(OnLostFocus);
 
            form.add_BeforeUnload(OnBeforeUnload);
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
        form.remove_AfterTransaction(OnAfterTransaction);
        form.GetElement("PCR-VENDOR").remove_LostFocus(OnLostFocus);
        form.remove_BeforeUnload(OnBeforeUnload);
    }
 
    public function OnLostFocus(sender: Object, e: RoutedEventArgs)
    {
        // Write out to console the selected vendor
        console.WriteLine("Vendor: "+ sender.Text);
 
        // If there is something there we proceed
        if(sender.Text != "")
        {
            // Fetch value for the vendor
            var vVendorGroup    = form.GetUserAttribute("vendor_group");
 
            // If no Vendor we default 1 for example purposes, normally we would fetch from Procure Group path
            if(vVendorGroup == "")
            {
                vVendorGroup = 1;
            }
 
            var vVendor         = sender.Text;
 
            // Write out our key values
            console.WriteLine("vVendorGroup: " + vVendorGroup);
            console.WriteLine("vVendor: " + vVendor);   
 
            // Build the Transaction API
            var sCall       = "&VEN-VENDOR-GROUP="+ vVendorGroup +"&VEN-VENDOR="+ vVendor;
 
            // Transaction API values
            var sForm       = "AP10.1";
            var sProd       = form.GetUserAttribute("productline");
            var sFunction   = "I";
            var sDesc       = "Vendor Inquire"; 
 
            // Issue the Transaction API
            var TransXml    = TransactionService_Execute(sForm, sProd, sFunction, sCall, sDesc);
 
            // Do we want to see the xml that came back?
            console.WriteLine(TransXml.OuterXml);
 
            // Fetch a node by name and write out the contents
            console.WriteLine("Contact: " + Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
            console.WriteLine("Phone: " + Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
            console.WriteLine("Account: " + Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));
 
            // Set the values to our custom elements
            form.SetCustomElementValue("CustContact", Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
            form.SetCustomElementValue("CustPhone", Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
            form.SetCustomElementValue("CustAccount", Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));
        }
    }
 
    // private functions
    private function AddFields()
    {
        AddLabel("CustContact","","Left",4,50,20,"blue",formGrid)
        AddLabel("CustPhone","","Left",5,50,20,"blue",formGrid)
        AddLabel("CustAccount","","Left",6,50,20,"blue",formGrid)
    }
 
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
        // test for good transaction
        if (e.TransactionError)
            return;
 
        // no action on delete
        if (e.FunctionCode == "D")
            return;
 
        // Fetch value for the vendor
        var vVendorGroup    = form.GetUserAttribute("vendor_group");
 
        // If no Vendor we default 1 for example purposes, normally we would fetch from Procure Group path
        if(vVendorGroup == "")
        {
            vVendorGroup = 1;
        }
 
        var vVendor         = form.GetTransactionValue("PCR-VENDOR");
 
        console.WriteLine("vVendorGroup: " + vVendorGroup);
        console.WriteLine("vVendor: " + vVendor);
 
        // Build the Transaction API
        var sCall       = "&VEN-VENDOR-GROUP="+ vVendorGroup +"&VEN-VENDOR="+ vVendor;
 
        // Transaction API values
        var sForm       = "AP10.1";
        var sProd       = form.GetUserAttribute("productline");
        var sFunction   = "I";
        var sDesc       = "Vendor Inquire"; 
 
        // Issue the Transaction API
        var TransXml    = TransactionService_Execute(sForm, sProd, sFunction, sCall, sDesc);
 
        // Do we want to see the xml that came back?
        console.WriteLine(TransXml.OuterXml);
 
        // Fetch a node by name and write out the contents
        console.WriteLine("Contact: " + Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
        console.WriteLine("Phone: " + Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
        console.WriteLine("Account: " + Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));
 
        form.SetCustomElementValue("CustContact", Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
        form.SetCustomElementValue("CustPhone", Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
        form.SetCustomElementValue("CustAccount", Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));
    }
 
    /**
     * AddLabel - Creates a label on the form
     * Parameters
     * sName        required    The unique label name
     * sCaption     required    The label text
     * sAlign       required    Alignment Right, Left or Center
     * nRow         required    Numeric row to place the label
     * nColumn      required    Numeric column to place the label
     * nColumnSpan  required    Numeric column span
     * bType        optional    Type, empty (for normal), bold or blue
     * oAddTo       required    Where to place label
     *
     * Example:     AddLabel("UniqueName","My new label","Right",1,50,12,"bold",formGrid)
    */
    private function AddLabel(sName,sCaption,sAlign,nRow,nColumn,nColumnSpan,bType,oAddTo)
    {
        // Define label
        var label       = new Label();                  // New label created
        label.Name      = sName;                        // Assign a name
        label.Content   = sCaption;                     // Assign a caption
        label.Padding   = new Thickness(1);             // Add padding
 
        label.VerticalContentAlignment = VerticalAlignment.Center;  // Center the alignment
 
        if(bType == "blue")
        {
            label.Style = StyleManager.StyleAdditionalInfo; // import Mango.UI.Core;  //blue label
        }
        if(bType == "bold")
        {
            label.Style = StyleManager.StyleEmphasized; // import Mango.UI.Core;  // bold label
        }
 
        if(sAlign == "Right")                           // Set the alignment of the caption within the label
            {label.HorizontalContentAlignment = HorizontalAlignment.Right}
        else if(sAlign == "Center")
            {label.HorizontalContentAlignment = HorizontalAlignment.Center}
        else
            {label.HorizontalContentAlignment = HorizontalAlignment.Left}
 
        Grid.SetRow(label, nRow);                       //Indicate the row for the label
        Grid.SetColumn(label, nColumn);                 //Indicate the starting column for the label
        Grid.SetColumnSpan(label, nColumnSpan);         //Indicate the column width of the label
        form.AddCustomElement(oAddTo, label);           //Add the label to the form
    }
 
    /**
     * TransactionService_Execute - This method returns xml from a transaction service call
     * Detail description
     * This method returns xml for the api details
     * @param      required     sForm, _TKN
     * @param      required     sProd, _PDL
     * @param      required     sFunction, FC
     * @param      required     sCall
     * @param      optional     sDesc
     * @access     private
     * @return     xml
    */
    private function TransactionService_Execute(sForm, sProd, sFunction, sCall, sDesc)
    {
        var s = "";
        var oXML;
 
        // Build the complete Transaction Service Call
        s = ScriptConstants.TransactionPath
        s += "?_PDL=" + sProd;
        s += "&_TKN=" + sForm
        if(sFunction == "Add" || sFunction == "A")
            {s += "&_EVT=ADD"}
        else
            {s += "&_EVT=CHG"}
        s += "&FC=" + sFunction;
        s += sCall;
        s += "&_LFN=ALL&_TDS=IGNORE&_OUT=XML&_EOT=TRUE";
 
        console.WriteLine("s: " + s);
 
        // Make the server request
        oXML = form.ServerRequest(s);
 
        // Determine if the Transaction Service Call processed
        if(!oXML)
        {
            console.WriteLine("The Transaction Service Call \n\n" + sDesc + "\n\nfailed to process.")
        }
        else if(Transaction_GetFieldValue(oXML, "MsgNbr") != "000")     // Determine if the Transaction Service Call worked
        {
            console.WriteLine(sForm + " MsgNbr: " + Transaction_GetFieldValue(oXML, "Message"));
        }
 
        return oXML;
    }
 
    private function Transaction_GetFieldValue(oData, sFind)
    {
        return oData.SelectSingleNode("//" + sFind).InnerText;
    }
 
} }
//-----------------------------------------------------------------------------
//	JScript Example
//	Created by: 	Josh Geving - Solutions Group
//
//	Description: 	PO20 - Gather additional fields from the vendor record and
//					dipslay them in the header as new labels
//
//	Optional:		form.GetUserAttribute("vendor_group");
//
//	Last Tested on Smart Office Version 10.0.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;

// New import to support StyleManager
import Mango.UI.Core;

package S3.Client.Forms.JScript {

class JjgPO20VendorInfo
{
	var console, form, formGrid;

	public function Init(element: Object, args: Object, controller: Object, debug: Object)
	{
		try {
			form = controller;
			formGrid = form.FormGrid;
			console = debug;

			// TODO Add your code here

			// Add additional fields
			AddFields();

			// Capture AfterTransaction
			form.add_AfterTransaction(OnAfterTransaction);

			// Support user leaving Vendor Field
			form.GetElement("PCR-VENDOR").add_LostFocus(OnLostFocus);

			form.add_BeforeUnload(OnBeforeUnload);

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup
		form.remove_AfterTransaction(OnAfterTransaction);
		form.GetElement("PCR-VENDOR").remove_LostFocus(OnLostFocus);
		form.remove_BeforeUnload(OnBeforeUnload);
	}

    public function OnLostFocus(sender: Object, e: RoutedEventArgs)
    {
    	// Write out to console the selected vendor
    	console.WriteLine("Vendor: "+ sender.Text);

    	// If there is something there we proceed
    	if(sender.Text != "")
    	{
			// Fetch value for the vendor
			var vVendorGroup 	= form.GetUserAttribute("vendor_group");

			// If no Vendor we default 1 for example purposes, normally we would fetch from Procure Group path
			if(vVendorGroup == "")
			{
				vVendorGroup = 1;
			}

			var vVendor 		= sender.Text;

			// Write out our key values
			console.WriteLine("vVendorGroup: " + vVendorGroup);
			console.WriteLine("vVendor: " + vVendor);	

			// Build the Transaction API
			var sCall 		= "&VEN-VENDOR-GROUP="+ vVendorGroup +"&VEN-VENDOR="+ vVendor;

			// Transaction API values
			var sForm		= "AP10.1";
			var sProd 		= form.GetUserAttribute("productline");
			var sFunction	= "I";
			var sDesc 		= "Vendor Inquire";	

			// Issue the Transaction API
			var TransXml 	= TransactionService_Execute(sForm, sProd, sFunction, sCall, sDesc);

			// Do we want to see the xml that came back?
			console.WriteLine(TransXml.OuterXml);

			// Fetch a node by name and write out the contents
			console.WriteLine("Contact: " + Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
			console.WriteLine("Phone: " + Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
			console.WriteLine("Account: " + Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));

			// Set the values to our custom elements
			form.SetCustomElementValue("CustContact", Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
			form.SetCustomElementValue("CustPhone", Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
			form.SetCustomElementValue("CustAccount", Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));
    	}
    }

	// private functions
	private function AddFields()
	{
		AddLabel("CustContact","","Left",4,50,20,"blue",formGrid)
		AddLabel("CustPhone","","Left",5,50,20,"blue",formGrid)
		AddLabel("CustAccount","","Left",6,50,20,"blue",formGrid)
	}

	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
		// test for good transaction
		if (e.TransactionError)
			return;

		// no action on delete
		if (e.FunctionCode == "D")
			return;

		// Fetch value for the vendor
		var vVendorGroup 	= form.GetUserAttribute("vendor_group");

		// If no Vendor we default 1 for example purposes, normally we would fetch from Procure Group path
		if(vVendorGroup == "")
		{
			vVendorGroup = 1;
		}

		var vVendor 		= form.GetTransactionValue("PCR-VENDOR");

		console.WriteLine("vVendorGroup: " + vVendorGroup);
		console.WriteLine("vVendor: " + vVendor);

		// Build the Transaction API
		var sCall 		= "&VEN-VENDOR-GROUP="+ vVendorGroup +"&VEN-VENDOR="+ vVendor;

		// Transaction API values
		var sForm		= "AP10.1";
		var sProd 		= form.GetUserAttribute("productline");
		var sFunction	= "I";
		var sDesc 		= "Vendor Inquire";	

		// Issue the Transaction API
		var TransXml 	= TransactionService_Execute(sForm, sProd, sFunction, sCall, sDesc);

		// Do we want to see the xml that came back?
		console.WriteLine(TransXml.OuterXml);

		// Fetch a node by name and write out the contents
		console.WriteLine("Contact: " + Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
		console.WriteLine("Phone: " + Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
		console.WriteLine("Account: " + Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));

		form.SetCustomElementValue("CustContact", Transaction_GetFieldValue(TransXml, "VEN-VENDOR-CONTCT"));
		form.SetCustomElementValue("CustPhone", Transaction_GetFieldValue(TransXml, "VEN-PHONE-NUM"));
		form.SetCustomElementValue("CustAccount", Transaction_GetFieldValue(TransXml, "VEN-VEND-ACCT"));
	}

	/**
	 * AddLabel - Creates a label on the form
	 * Parameters
	 * sName      	required	The unique label name
	 * sCaption     required	The label text
	 * sAlign      	required	Alignment Right, Left or Center
	 * nRow      	required	Numeric row to place the label
	 * nColumn      required	Numeric column to place the label
	 * nColumnSpan  required	Numeric column span
	 * bType     	optional	Type, empty (for normal), bold or blue
	 * oAddTo		required	Where to place label
	 *
	 * Example:		AddLabel("UniqueName","My new label","Right",1,50,12,"bold",formGrid)
	*/
	private function AddLabel(sName,sCaption,sAlign,nRow,nColumn,nColumnSpan,bType,oAddTo)
	{
		// Define label
		var label 		= new Label();					// New label created
		label.Name 		= sName;						// Assign a name
		label.Content 	= sCaption;						// Assign a caption
		label.Padding 	= new Thickness(1);				// Add padding

		label.VerticalContentAlignment = VerticalAlignment.Center;	// Center the alignment

		if(bType == "blue")
		{
			label.Style = StyleManager.StyleAdditionalInfo; // import Mango.UI.Core;  //blue label
		}
		if(bType == "bold")
		{
			label.Style = StyleManager.StyleEmphasized;	// import Mango.UI.Core;  // bold label
		}

		if(sAlign == "Right")							// Set the alignment of the caption within the label
			{label.HorizontalContentAlignment = HorizontalAlignment.Right}
		else if(sAlign == "Center")
			{label.HorizontalContentAlignment = HorizontalAlignment.Center}
		else
			{label.HorizontalContentAlignment = HorizontalAlignment.Left}

		Grid.SetRow(label, nRow);						//Indicate the row for the label
		Grid.SetColumn(label, nColumn);					//Indicate the starting column for the label
		Grid.SetColumnSpan(label, nColumnSpan);			//Indicate the column width of the label
		form.AddCustomElement(oAddTo, label);			//Add the label to the form
	}

	/**
	 * TransactionService_Execute - This method returns xml from a transaction service call
	 * Detail description
	 * This method returns xml for the api details
	 * @param      required 	sForm, _TKN
	 * @param      required		sProd, _PDL
	 * @param      required		sFunction, FC
	 * @param      required		sCall
	 * @param      optional		sDesc
	 * @access     private
	 * @return     xml
	*/
	private function TransactionService_Execute(sForm, sProd, sFunction, sCall, sDesc)
	{
		var s = "";
		var oXML;

		// Build the complete Transaction Service Call
		s = ScriptConstants.TransactionPath
		s += "?_PDL=" + sProd;
		s += "&_TKN=" + sForm
		if(sFunction == "Add" || sFunction == "A")
			{s += "&_EVT=ADD"}
		else
			{s += "&_EVT=CHG"}
		s += "&FC=" + sFunction;
		s += sCall;
		s += "&_LFN=ALL&_TDS=IGNORE&_OUT=XML&_EOT=TRUE";

		console.WriteLine("s: " + s);

		// Make the server request
		oXML = form.ServerRequest(s);

		// Determine if the Transaction Service Call processed
		if(!oXML)
		{
			console.WriteLine("The Transaction Service Call \n\n" + sDesc + "\n\nfailed to process.")
		}
		else if(Transaction_GetFieldValue(oXML, "MsgNbr") != "000")		// Determine if the Transaction Service Call worked
		{
			console.WriteLine(sForm + " MsgNbr: " + Transaction_GetFieldValue(oXML, "Message"));
		}

		return oXML;
	}

	private function Transaction_GetFieldValue(oData, sFind)
	{
		return oData.SelectSingleNode("//" + sFind).InnerText;
	}

} }

 

GL40 Red Comments Indicator – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

Change the COMMENTS output field to Red and Bold.

 

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
//-----------------------------------------------------------------------------
//  JScript Example
//  Created by:     Josh Geving - Solutions Group
//
//  Description:    Change the COMMENTS output field to Red and Bold
//
//  Last Tested on Smart Office Version 10.0.1.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
 
import Mango.UI.Core;
 
package S3.Client.Forms.JScript {
 
class JjgGL40Comments
{
    var console, form, formGrid;
 
    public function Init(element: Object, args: Object, controller: Object, debug: Object)
    {
        try {
            form = controller;
 
            formGrid = form.FormGrid;
            console = debug;
 
            // TODO Add your code here
            form.add_AfterTransaction(OnAfterTransaction);
 
            form.add_BeforeUnload(OnBeforeUnload);
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
        form.remove_AfterTransaction(OnAfterTransaction);
        form.remove_BeforeUnload(OnBeforeUnload);
    }
 
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
            // The Content comes from the transaction, so we set it here if it has a value
            var vCommentTransValue = form.GetTransactionValue("COMMENTS-MSG");
 
            // If the value from the transaction is Comments Exis we set a new value before it
            // goes to display
            if(vCommentTransValue == "Comments Exis")
            {
                form.SetTransactionValue("COMMENTS-MSG", "Comments"); 
 
                // Style it Red and Bold
                ChangeLabelStyle();
            }
    }
 
    // private functions
 
    private function ChangeLabelStyle()
    {
            // Grab the comment label
            var lblComments         = form.GetElement("COMMENTS-MSG");
 
            // Change its style
            lblComments.Foreground = System.Windows.Media.Brushes.Red;
            lblComments.FontWeight = FontWeights.Bold;
    }
 
} }
//-----------------------------------------------------------------------------
//	JScript Example
//	Created by: 	Josh Geving - Solutions Group
//
//	Description: 	Change the COMMENTS output field to Red and Bold
//
//	Last Tested on Smart Office Version 10.0.1.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;

import Mango.UI.Core;

package S3.Client.Forms.JScript {

class JjgGL40Comments
{
	var console, form, formGrid;

	public function Init(element: Object, args: Object, controller: Object, debug: Object)
	{
		try {
			form = controller;

			formGrid = form.FormGrid;
			console = debug;

			// TODO Add your code here
			form.add_AfterTransaction(OnAfterTransaction);

			form.add_BeforeUnload(OnBeforeUnload);

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup
		form.remove_AfterTransaction(OnAfterTransaction);
		form.remove_BeforeUnload(OnBeforeUnload);
	}

	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
			// The Content comes from the transaction, so we set it here if it has a value
			var vCommentTransValue = form.GetTransactionValue("COMMENTS-MSG");

			// If the value from the transaction is Comments Exis we set a new value before it
			// goes to display
			if(vCommentTransValue == "Comments Exis")
			{
				form.SetTransactionValue("COMMENTS-MSG", "Comments"); 

				// Style it Red and Bold
				ChangeLabelStyle();
			}
	}

	// private functions

	private function ChangeLabelStyle()
	{
			// Grab the comment label
			var lblComments 		= form.GetElement("COMMENTS-MSG");

			// Change its style
			lblComments.Foreground = System.Windows.Media.Brushes.Red;
			lblComments.FontWeight = FontWeights.Bold;
	}

} }

 

Red Label Example – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

The following code is an example of how to create a red label on a form using the Scripting Tool.

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
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
            // The Content comes from the transaction, so we set it here if it has a value
            var vCommentTransValue = form.GetTransactionValue("COMMENTS-MSG");
 
            // If the value from the transaction is Comments Exis we set a new value before it
            // goes to display
            if(vCommentTransValue == "Comments Exis")
            {
                form.SetTransactionValue("COMMENTS-MSG", "Comments"); 
 
                // Style it Red and Bold
                ChangeLabelStyle();
            }           
    }
 
    // private functions
 
    private function ChangeLabelStyle()
    {
            // Grab the comment label
            var lblComments         = form.GetElement("COMMENTS-MSG");
 
            // Change its style
            lblComments.Foreground = System.Windows.Media.Brushes.Red;
            lblComments.FontWeight = FontWeights.Bold;
    }
	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
			// The Content comes from the transaction, so we set it here if it has a value
			var vCommentTransValue = form.GetTransactionValue("COMMENTS-MSG");

			// If the value from the transaction is Comments Exis we set a new value before it
			// goes to display
			if(vCommentTransValue == "Comments Exis")
			{
				form.SetTransactionValue("COMMENTS-MSG", "Comments"); 

				// Style it Red and Bold
				ChangeLabelStyle();
			}   		
	}

	// private functions

	private function ChangeLabelStyle()
	{
			// Grab the comment label
			var lblComments 		= form.GetElement("COMMENTS-MSG");

			// Change its style
			lblComments.Foreground = System.Windows.Media.Brushes.Red;
			lblComments.FontWeight = FontWeights.Bold;
	}

PO20 Attachment Count Display – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

After a transaction, fetches a count of the Purchase Order Header Attachments, then displays the count in a new label next to the comment button.

 

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
//-----------------------------------------------------------------------------
//  JScript Example
//  Created by:     Josh Geving - Solutions Group
//
//  Description:    PO20 - After a transaction, fetches a count of the Purchase
//                  Order Header Attachments, then displays the count in a new
//                  label next to the comment button
//
//  Last Tested on Smart Office Version 10.0.1.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
 
import Mango.UI.Core;
 
package S3.Client.Forms.JScript {
 
class JjgAttachmentCount
{
    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);
 
            // TODO Add your code here
 
            // Add new fields to form
            AddFields();
 
            form.add_AfterTransaction(OnAfterTransaction);
            form.add_BeforeUnload(OnBeforeUnload);
            console.WriteLine("Script initialized.");
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", null, e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
        form.remove_AfterTransaction(OnAfterTransaction);
        form.remove_BeforeUnload(OnBeforeUnload);
    }
 
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
        // Form Keys
        var vCompany    = form.GetTransactionValue("PCR-COMPANY");
        var vPoNumber   = form.GetTransactionValue("PCR-PO-NUMBER");
 
        // build up the DME call for first pass
        var transAPI1 = "/cgi-lawson/getattachrec.exe?_OPM=C&_PDL=" +
            form.GetUserAttribute("productline") +
            "&_FN=PURCHORDER&_AOBJ=TRUE&_IN=PCRSET1&_ATYP=U&_DRIL=TRUE" +
            "&_ON=Purchase+Order+Header+Attachments&_ATTR=TRUE&_TYP=URL&K4=0" +
            "&K3=" + vPoNumber +
            "&_AUDT=I&K2=&_OUT=XML&K1=" + vCompany +
            "&_ECODE=FALSE";
 
        // Make the server request
 
        // Make the server request, record the time it took
        var bTime   = new Date().getTime();
        var transXml1       = ScriptUtil.ServerRequest(transAPI1);
        var eTime   = new Date().getTime();
        console.WriteLine("API Execution Time: " + (eTime-bTime)/1000 + "seconds");
 
        if (!transXml1) return;
 
        // Fetch a count from the xml, 1 means there are none
        var vCount = transXml1.SelectNodes("//AttName").Count;
 
        var existingLabel = form.GetCustomElement("AttachCountLabel");
        if (existingLabel != null)
        {
            form.SetCustomElementValue(existingLabel.Name, vCount-1);
        }
    }
 
    // private functions
 
    private function AddFields()
    {
        // Add a label to display the attachment count
        AddLabel("AttachCountLabel","-","Left",7,57,3,"",formGrid);
    }
 
    /**
     * AddLabel - Creates a label on the form
     * Parameters
     * sName        required    The unique label name
     * sCaption     required    The label text
     * sAlign       required    Alignment Right, Left or Center
     * nRow         required    Numeric row to place the label
     * nColumn      required    Numeric column to place the label
     * nColumnSpan  required    Numeric column span
     * bType        optional    Type, empty (for normal), bold or blue
     * oAddTo       required    Where to place label
     *
     * Example:     AddLabel("UniqueName","My new label","Right",1,50,12,"bold",formGrid)
    */
    private function AddLabel(sName,sCaption,sAlign,nRow,nColumn,nColumnSpan,bType,oAddTo)
    {
        // Define label
        var label       = new Label();                  // New label created
        label.Name      = sName;                        // Assign a name
        label.Content   = sCaption;                     // Assign a caption
        label.Padding   = new Thickness(1);             // Add padding
 
        label.VerticalContentAlignment = VerticalAlignment.Top;
 
        if(bType == "blue")
        {
            label.Style = StyleManager.StyleAdditionalInfo; // import Mango.UI.Core;  //blue label
        }
        if(bType == "bold")
        {
            label.Style = StyleManager.StyleEmphasized; // import Mango.UI.Core;  // bold label
        }
 
        if(sAlign == "Right")                           // Set the alignment of the caption within the label
            {label.HorizontalContentAlignment = HorizontalAlignment.Right}
        else if(sAlign == "Center")
            {label.HorizontalContentAlignment = HorizontalAlignment.Center}
        else
            {label.HorizontalContentAlignment = HorizontalAlignment.Left}
 
        Grid.SetRow(label, nRow);                       //Indicate the row for the label
        Grid.SetColumn(label, nColumn);                 //Indicate the starting column for the label
        Grid.SetColumnSpan(label, nColumnSpan);         //Indicate the column width of the label
        form.AddCustomElement(oAddTo, label);           //Add the label to the form
    }                                                                                   
 
} }
//-----------------------------------------------------------------------------
//	JScript Example
//	Created by: 	Josh Geving - Solutions Group
//
//	Description: 	PO20 - After a transaction, fetches a count of the Purchase
//					Order Header Attachments, then displays the count in a new
//					label next to the comment button
//
//	Last Tested on Smart Office Version 10.0.1.1.5
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;

import Mango.UI.Core;

package S3.Client.Forms.JScript {

class JjgAttachmentCount
{
	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);

			// TODO Add your code here

			// Add new fields to form
			AddFields();

			form.add_AfterTransaction(OnAfterTransaction);
			form.add_BeforeUnload(OnBeforeUnload);
			console.WriteLine("Script initialized.");

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", null, e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup
		form.remove_AfterTransaction(OnAfterTransaction);
		form.remove_BeforeUnload(OnBeforeUnload);
	}

	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
		// Form Keys
		var vCompany 	= form.GetTransactionValue("PCR-COMPANY");
		var vPoNumber 	= form.GetTransactionValue("PCR-PO-NUMBER");

		// build up the DME call for first pass
		var transAPI1 = "/cgi-lawson/getattachrec.exe?_OPM=C&_PDL=" +
			form.GetUserAttribute("productline") +
			"&_FN=PURCHORDER&_AOBJ=TRUE&_IN=PCRSET1&_ATYP=U&_DRIL=TRUE" +
			"&_ON=Purchase+Order+Header+Attachments&_ATTR=TRUE&_TYP=URL&K4=0" +
			"&K3=" + vPoNumber +
			"&_AUDT=I&K2=&_OUT=XML&K1=" + vCompany +
			"&_ECODE=FALSE";

		// Make the server request

		// Make the server request, record the time it took
		var bTime 	= new Date().getTime();
		var transXml1 		= ScriptUtil.ServerRequest(transAPI1);
		var eTime 	= new Date().getTime();
		console.WriteLine("API Execution Time: " + (eTime-bTime)/1000 + "seconds");

		if (!transXml1) return;

		// Fetch a count from the xml, 1 means there are none
		var vCount = transXml1.SelectNodes("//AttName").Count;

   		var existingLabel = form.GetCustomElement("AttachCountLabel");
   		if (existingLabel != null)
   		{
      		form.SetCustomElementValue(existingLabel.Name, vCount-1);
   		}
	}

	// private functions

	private function AddFields()
	{
		// Add a label to display the attachment count
		AddLabel("AttachCountLabel","-","Left",7,57,3,"",formGrid);
	}

	/**
	 * AddLabel - Creates a label on the form
	 * Parameters
	 * sName      	required	The unique label name
	 * sCaption     required	The label text
	 * sAlign      	required	Alignment Right, Left or Center
	 * nRow      	required	Numeric row to place the label
	 * nColumn      required	Numeric column to place the label
	 * nColumnSpan  required	Numeric column span
	 * bType     	optional	Type, empty (for normal), bold or blue
	 * oAddTo		required	Where to place label
	 *
	 * Example:		AddLabel("UniqueName","My new label","Right",1,50,12,"bold",formGrid)
	*/
	private function AddLabel(sName,sCaption,sAlign,nRow,nColumn,nColumnSpan,bType,oAddTo)
	{
		// Define label
		var label 		= new Label();					// New label created
		label.Name 		= sName;						// Assign a name
		label.Content 	= sCaption;						// Assign a caption
		label.Padding 	= new Thickness(1);				// Add padding

		label.VerticalContentAlignment = VerticalAlignment.Top;

		if(bType == "blue")
		{
			label.Style = StyleManager.StyleAdditionalInfo; // import Mango.UI.Core;  //blue label
		}
		if(bType == "bold")
		{
			label.Style = StyleManager.StyleEmphasized;	// import Mango.UI.Core;  // bold label
		}

		if(sAlign == "Right")							// Set the alignment of the caption within the label
			{label.HorizontalContentAlignment = HorizontalAlignment.Right}
		else if(sAlign == "Center")
			{label.HorizontalContentAlignment = HorizontalAlignment.Center}
		else
			{label.HorizontalContentAlignment = HorizontalAlignment.Left}

		Grid.SetRow(label, nRow);						//Indicate the row for the label
		Grid.SetColumn(label, nColumn);					//Indicate the starting column for the label
		Grid.SetColumnSpan(label, nColumnSpan);			//Indicate the column width of the label
		form.AddCustomElement(oAddTo, label);			//Add the label to the form
	}																					

} }

 

 

 

AP10 Prevent Duplicate Vendors – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

When entering a new vendor the vendor name is queried against APVENMAST to verify it is unique, the addr1 field is also checked to make sure the address is unique.  If either of the above are found to be a match the transaction is stopped.

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
//-----------------------------------------------------------------------------
//  JScript Example
//  Created by:     Josh Geving - Solutions Group
//  
//  Description:    When entering a new vendor the vendor name is queried
//              against APVENMAST to verify it is unique, the addr1
//              field is also checked to make sure the address is unique
//              If either of the above are found to be a match the
//              transaction is stopped
//
//  Last Tested on Smart Office Version 9.1.3
//-----------------------------------------------------------------------------
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 JjgAP10PreventDupes
{
    var console, form, formGrid;
 
    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);
 
            // TODO Add your code here
 
            // hookup some events
            form.add_BeforeTransaction(OnBeforeTransaction);
 
            // END CODE
 
            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
        if (e.FunctionCode == "A") 
        {
            try {
                var vVendorGroup    = form.GetElementValue("VEN-VENDOR-GROUP");
                var vVendorName     = form.GetElementValue("VEN-VENDOR-VNAME");
                var vVendorAddr1    = form.GetElementValue("VDR-ADDR1");
                var vVendor         = form.GetElementValue("VEN-VENDOR");
                var vendorList      = "";
                var message         = "";
 
                // build up the Data Service call
                var sProd       = form.GetUserAttribute("productline");
                var sFile       = "APVENMAST";
                var sField      = "VENDOR-GROUP;VENDOR;VENDOR-VNAME";
                var sIndex      = "VENSET1&KEY=" + vVendorGroup;
                var sCond       = "";
                var sSelect     = "VENDOR-VNAME~" + vVendorName;
                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)
                {
                    for(var i = 0; i < aDataAPI.length; i++)
                    {
                        console.WriteLine(aDataAPI[i]);
                        vendorList += aDataAPI[i]+"\n";
                    }
 
                    var message = "Tax ID supplied matches vendor(s)\n: " + vendorList + "\nTransaction stopped.";
                    ConfirmDialog.ShowWarningDialog("Matching Vendor(s)", message, null);
 
                    form.SetMessage(message);
                    e.Cancel = true;
                }
                else{
                    console.WriteLine("***No Records***");
                }
 
            } 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);
    }
 
    /**
     * 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 FormatException(funcName, prefMsg, e)
    {
        var errMsg = (typeof(prefMsg)=="string" ? prefMsg+"\n" : "Exception encountered:\n");
        errMsg += "  Class:\t\tJjgAP10PreventDupes\n";
        errMsg += "  Function:\t"+funcName+"\n";
        errMsg += "  Name:\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;
    }
} }
//-----------------------------------------------------------------------------
//	JScript Example
//	Created by: 	Josh Geving - Solutions Group
//	
//	Description: 	When entering a new vendor the vendor name is queried
//				against APVENMAST to verify it is unique, the addr1
//				field is also checked to make sure the address is unique
//				If either of the above are found to be a match the
//				transaction is stopped
//
//	Last Tested on Smart Office Version 9.1.3
//-----------------------------------------------------------------------------
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 JjgAP10PreventDupes
{
	var console, form, formGrid;

	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);

			// TODO Add your code here

			// hookup some events
			form.add_BeforeTransaction(OnBeforeTransaction);

			// END CODE

			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
		if (e.FunctionCode == "A") 
		{
			try {
				var vVendorGroup 	= form.GetElementValue("VEN-VENDOR-GROUP");
				var vVendorName		= form.GetElementValue("VEN-VENDOR-VNAME");
				var vVendorAddr1	= form.GetElementValue("VDR-ADDR1");
				var vVendor			= form.GetElementValue("VEN-VENDOR");
				var vendorList		= "";
				var message			= "";

				// build up the Data Service call
				var sProd 		= form.GetUserAttribute("productline");
				var sFile 		= "APVENMAST";
				var sField		= "VENDOR-GROUP;VENDOR;VENDOR-VNAME";
				var sIndex 		= "VENSET1&KEY=" + vVendorGroup;
				var sCond 		= "";
				var sSelect		= "VENDOR-VNAME~" + vVendorName;
				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)
				{
					for(var i = 0; i < aDataAPI.length; i++)
					{
						console.WriteLine(aDataAPI[i]);
						vendorList += aDataAPI[i]+"\n";
					}

					var message = "Tax ID supplied matches vendor(s)\n: " + vendorList + "\nTransaction stopped.";
					ConfirmDialog.ShowWarningDialog("Matching Vendor(s)", message, null);

					form.SetMessage(message);
					e.Cancel = true;
				}
				else{
					console.WriteLine("***No Records***");
				}

			} 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);
	}

	/**
	 * 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 FormatException(funcName, prefMsg, e)
	{
		var errMsg = (typeof(prefMsg)=="string" ? prefMsg+"\n" : "Exception encountered:\n");
		errMsg += "  Class:\t\tJjgAP10PreventDupes\n";
		errMsg += "  Function:\t"+funcName+"\n";
		errMsg += "  Name:\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;
	}
} }

 

AP10 Verify Unique Tax ID – Smart Office Scripting

in Lawson, Smart Office, Smart Office Scripting / No Comments

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.

 

 

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;
    }
} }
//-----------------------------------------------------------------------------
//	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;
	}
} }

 

 

Apply a Mask to the Vendor Tax ID Field

in Lawson, Smart Office, Smart Office Scripting / No Comments

In this example we were asked to mask the Tax ID field on the Lawson S3 Vendor screen (AP10).  Under certain circumstances it may be necessary to protect this data. This was part of a project to provide users with a vendor look-up screen and verification of the vendor based on the last 4 digits of the Tax ID was part of the plan.

Here is the script that was used to mask the Tax ID data if a Tax ID was associated with the record. The field was also made output-only.

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
//-----------------------------------------------------------------------------
//  Smart Office Script Example
//  Created by:     Josh Geving
//  
//  Description:    Mask the Tax ID field and only display the last 4 
//                  characters
//
//  Last Tested:    9.1.3
//-----------------------------------------------------------------------------
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 JJG_AP10_TAXIDMASK
{
    var console, form, formGrid;
 
    public function Init(element: Object, args: Object, controller: Object, debug: Object)
    {
        try {
            form = controller;
            formGrid = form.FormGrid;
            console = debug;
 
            // TODO Add your code here
 
            //lets make the field output only while we are at it
            var TaxIdField      = form.GetElement("VEN-TAX-ID");
            TaxIdField.IsEnabled = false;
 
            form.add_AfterTransaction(OnAfterTransaction);
 
            form.add_BeforeUnload(OnBeforeUnload);
 
        } catch (e) {
            console.WriteLine(ScriptUtil.FormatException("Init", e));
        }
    }
 
    // event handlers
    public function OnBeforeUnload(sender: Object, e: FormEventArgs)
    {
        // perform cleanup
 
        form.remove_BeforeUnload(OnBeforeUnload);
        form.remove_AfterTransaction(OnAfterTransaction);
    }
 
    // private functions
 
    public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
    {
        //store the tax id
        var vTaxId          = form.GetTransactionValue("VEN-TAX-ID");
 
        //set a variable that will be the masked version
        var vAsterisks      = "";
 
        //the length of the masked string as the fill
        var vFillLength     = (vTaxId.length-4);
 
        //perform a loop to fill in the asterisks based on the tax id length
        var i               = 0;
        while (i <= vFillLength){
            vAsterisks += "*";
            i++;
        }
 
        //the new masked tax id displaying the last 4 characters of the tax id
        var vMasked         = vAsterisks + vTaxId.substring(vTaxId.length-4,vTaxId.length);
 
        //set the value to the form and transaction
        form.SetElementValue("VEN-TAX-ID", vMasked);
        form.SetTransactionValue("VEN-TAX-ID", vMasked);
    }
} }
//-----------------------------------------------------------------------------
//	Smart Office Script Example
//	Created by: 	Josh Geving
//	
//	Description: 	Mask the Tax ID field and only display the last 4 
//					characters
//
//	Last Tested: 	9.1.3
//-----------------------------------------------------------------------------
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 JJG_AP10_TAXIDMASK
{
	var console, form, formGrid;

	public function Init(element: Object, args: Object, controller: Object, debug: Object)
	{
		try {
			form = controller;
			formGrid = form.FormGrid;
			console = debug;

			// TODO Add your code here

			//lets make the field output only while we are at it
			var TaxIdField 		= form.GetElement("VEN-TAX-ID");
			TaxIdField.IsEnabled = false;

			form.add_AfterTransaction(OnAfterTransaction);

			form.add_BeforeUnload(OnBeforeUnload);

		} catch (e) {
			console.WriteLine(ScriptUtil.FormatException("Init", e));
		}
	}

	// event handlers
	public function OnBeforeUnload(sender: Object, e: FormEventArgs)
	{
		// perform cleanup

		form.remove_BeforeUnload(OnBeforeUnload);
		form.remove_AfterTransaction(OnAfterTransaction);
	}

	// private functions

	public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
	{
		//store the tax id
		var vTaxId	 		= form.GetTransactionValue("VEN-TAX-ID");

		//set a variable that will be the masked version
		var vAsterisks		= "";

		//the length of the masked string as the fill
		var vFillLength 	= (vTaxId.length-4);

		//perform a loop to fill in the asterisks based on the tax id length
		var i				= 0;
		while (i <= vFillLength){
			vAsterisks += "*";
			i++;
		}

		//the new masked tax id displaying the last 4 characters of the tax id
		var vMasked 		= vAsterisks + vTaxId.substring(vTaxId.length-4,vTaxId.length);

		//set the value to the form and transaction
		form.SetElementValue("VEN-TAX-ID", vMasked);
		form.SetTransactionValue("VEN-TAX-ID", vMasked);
	}
} }