UXDE dot Net Wordpress Themes

Posts Selected From the Category "Lawson"

Data Mining Engine (DME) Code for Design Studio Scripting

in Design Studio, Lawson / No Comments

I am always asked by developers new to Design Studio how to perform a DME call to retrieve data within Lawson S3 applications.  I came across this code years ago and it has proven invaluable for this task. You can attach directly to a form as is or use it as an Include file but it facilitates the processing of a DME API into Lawson for use with an S3 form.  Below the code I have attached a simple example where this code is used.

DME Code (Updated on April 16, 2013, now compatible with 10.0.3 and 10.1 Portal)

 

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
/************************************************************
********************* DME OBJECT CODE ***********************
***************** SIMPLIFIES PERFORMING A DME ***************
***************** UPDATED APRIL 2013 for 10.0.3 *************
*************************************************************
*************************************************************   
************************************************************/
 
/************************************************************
    Function: exampleDme()
 
    Purpose:  Simple example usign the dme code
************************************************************/
function exampleDme()
{
    //fetch the effective date used so we can send a change action
    var vCo     = portalWnd.oUserProfile.getAttribute("company");
    var vJobCode    = "110";
 
    //set object and table/prodline
    var empDMEObj   = new DMEObject("JOBCODE", strPDL);
 
    //set an index
    empDMEObj.setIndex("JBCSET1&KEY=" + vCo + "=" + vJobCode);
 
    //tell it what fields to fetch
    empDMEObj.addField("EFFECTIVE-DATE");
 
    //prompt("obj",empDMEObj.toString());
    empDMEObj.execute();
 
    //grab a field from the dme result
    var vEffectDateHR06 = empDMEObj.getField("EFFECTIVE-DATE"); 
 
    alert(vEffectDateHR06);
}
 
/************************************************************
    Function: getVarFromString
 
    Purpose:  get the variables from the search string
 
    Example:  var vCompany = getVarFromString("Company",parent.location.search);
************************************************************/
function getVarFromString(varName,str)
{
    str+='&'
    reStr="(?:\\&|\\?|^)" + varName + "=(.*?)(?:\\&|$)"
    var re=new RegExp(reStr,"gi")
    if(re.test(str))
        return RegExp.$1
    else
        return ""
}
 
/************************************************************
    Function: getDMEColumnIndex(pColumns)
 
    Purpose:  Helper Method used assist in getting DME record data as seen on pg 114 of 
          Design Studio User Guide
************************************************************/
function getDMEColumnIndex(pColumns)
{
    var vIndex = new Array();
    for (var i=0; i<pColumns.length; i++)
    {
        var vLabel = pColumns[i].getAttribute("header").toUpperCase().split("_").join("-");
        vIndex[vLabel] = i;
    }
    return vIndex;
}
 
/************************************************************
    Function: getNodeValue(pNode)
 
    Purpose:  Helper Method used assist in getting DME field data as seen on pg 114 of
          Design Studio User Guide
************************************************************/
function getNodeValue(pNode)
{
    for (var i=0; i<pNode.childNodes.length; i++)
    {
        if (pNode.childNodes[i].nodeType == 4)
        {
            return pNode.childNodes[i].nodeValue;
        }
    }
}
 
/************************************************************
    Function: DMEObject
 
    Purpose:  Constructor.  Return a new DMEObject for a file(table) and productline.
          Initialize your instance variables.
************************************************************/
function DMEObject(pFile, pPDL)
{
    this.file = pFile;
    this.pdl = pPDL;
    this.index = "";
    this.conditions = "";
    this.fields = "";
    this.select = "";
    this.optParams= "";
    this.dmeString = "";
    this.records = null;
    this.columns = new Array();
    this.length = 0;
    this.maxRecords = 9999;
    this.success = false;
}
 
/************************************************************
    Function: setIndex(pIndex)
 
    Purpose:  Instance method for DMEObject.  Takes in a predefined index and sets in in 
          the object..
************************************************************/
DMEObject.prototype.setIndex = function(pIndex)
{
    this.index = pIndex;
 
    return true;
}
 
/************************************************************
    Function: setIndex(pIndex)
 
    Purpose:  Instance method for DMEObject.  Takes in a predefined index and sets in in 
          the object..
************************************************************/
DMEObject.prototype.setOptParams = function(pOptParams)
{
    this.optParams = pOptParams;
 
    return true;
}
 
/************************************************************
    Function: setConditions(pConditions)
 
    Purpose:  Instance method for DMEObject.  Takes in a predefined Conditions and sets in in 
          the object..
************************************************************/
DMEObject.prototype.setConditions = function(pConditions)
{
    this.conditions = pConditions;
 
    return true;
}
 
/************************************************************
    Function: setSelect(pSelect)
 
    Purpose:  Instance method for DMEObject.  Takes in a predefined index and sets in in 
          the object..
************************************************************/
DMEObject.prototype.setSelect = function(pSelect)
{
    this.select= pSelect;
 
    return true;
}
 
/************************************************************
    Function: addField(pField, pFieldValue)
 
    Purpose:  Instance method for DMEObject.  Takes in a field name and adds it to the 
          fields portion of the DME string.
************************************************************/
DMEObject.prototype.addField = function(pField)
{
    this.fields += pField+";";
 
    return true;
}
 
/************************************************************
    Function: getField(pField)
 
    Purpose:  Instance method for DMEObject.  Takes in a field name as a parameter and 
          return's it's value from the DME String.  If pRelRecTable is populated, pField
          will be ignored and an array will be passed back.
************************************************************/
DMEObject.prototype.getField = function(pField, pRow, pRelRecTable)
{
    var rFieldValue;
 
    if ((pRow == undefined) ||
        (pRow == null))
    {
        pRow = 0;
    }
    if ((pRelRecTable == undefined) ||
        (pRelRecTable == null))
    {
        pRelRecTable = "";
    }
 
    //if it's not an empty string, we'll return the value from the related record tables
    if (pRelRecTable != "")
    {
        var vNewRelRecsArray = new Array();
        var vRelRecsArray = this.returnRecords[pRow].getElementsByTagName("RELRECS");
//alert(this.returnRecords[0].getElementsByTagName("RELRECS")[0].getElementsByTagName("RELREC")[1].getElementsByTagName("COL")[1].childNodes[0].nodeValue)
        //search each related table record set for one that matches pRelRecTable
        for(var i=0; i < vRelRecsArray.length; i++)
        {
            if (vRelRecsArray[i].getAttribute("name").toUpperCase().split("_").join("-") == pRelRecTable.toUpperCase())
            {
                var vRelRecArray = vRelRecsArray[i].getElementsByTagName("RELREC");
                //search specific related table record set's values
                for(var j=0; j < vRelRecArray.length; j++)
                {
                    var vNewRelRecArray = new Array();
                    var vRelRecColArray = vRelRecArray[j].getElementsByTagName("COL");
 
                    for(var k=0; k < vRelRecColArray.length; k++)
                    {
                        var vRelRecColValue = vRelRecColArray[k].childNodes[0].nodeValue;
                        vNewRelRecArray.push(vRelRecColValue);
                    }
                    vNewRelRecsArray.push(vNewRelRecArray)
                }
 
                break;
            }
        }
        rFieldValue = vNewRelRecsArray;
    }
    else
    {
        var vRecord = this.returnRecords[pRow].getElementsByTagName("COL");
 
        rFieldValue = getNodeValue(vRecord[this.columns[pField]]);
    }
 
    return (rFieldValue);
}
 
/************************************************************
    Function: BuildDMEString()
 
    Purpose:  Helper class method for DMEObject to build an DME string based on an DMEObject 
          passed in.  Could be used stand-alone.
************************************************************/
DMEObject.BuildDMEString = function(vDMEObject)
{
    var vDMEString = portalWnd.DMEPath 
             + "?PROD=" + vDMEObject.pdl
             + "&FILE=" + vDMEObject.file
             + "&INDEX=" + vDMEObject.index
             + "&COND=" + vDMEObject.conditions
             + "&FIELD=" + vDMEObject.fields
             + "&SELECT=" + vDMEObject.select
             + "&MAX=" + vDMEObject.maxRecords
             + vDMEObject.optParams
             +"&OUT=XML&DELIM="+(new Date()).getTime();
 
    //time was added to the unused field "DELIM" so it forces the DME to not used the cached data
 
    return vDMEString;
}
 
/************************************************************
    Function: execute()
 
    Purpose:  Instance method to execute this DME call.  Returns true on success, false on any 
          failure
************************************************************/
DMEObject.prototype.execute = function()
{
    this.dmeString = DMEObject.BuildDMEString(this);
 
    //execute http post
    var vDMEInfo = portalWnd.httpRequest(this.dmeString);
    //if the status exists, there was an error in the system, otherwise proceed to pull data out
    if (vDMEInfo.status)
    {
        this.success = false;
    }
    else
    {
        var xmlObj = new portalWnd.DataStorage(vDMEInfo);
        this.returnRecords = xmlObj.document.getElementsByTagName("RECORD");
        this.columns = getDMEColumnIndex(xmlObj.document.getElementsByTagName("COLUMN"));
        this.length = this.returnRecords.length;
    }
    //return true if it was successful and false if it wasnt    
    return this.success;
}
 
/************************************************************
    Function: toString()
 
    Purpose:  Instance method to aid in debugging.  Returns the current DME string for the
          the fields that have been added to the object so far.
************************************************************/
DMEObject.prototype.toString = function()
{
    this.dmeString = DMEObject.BuildDMEString(this);
    return this.dmeString;
}
/************************************************************
********************* DME OBJECT CODE ***********************
***************** SIMPLIFIES PERFORMING A DME ***************
***************** UPDATED APRIL 2013 for 10.0.3 *************
*************************************************************
*************************************************************	
************************************************************/

/************************************************************
	Function: exampleDme()

	Purpose:  Simple example usign the dme code
************************************************************/
function exampleDme()
{
	//fetch the effective date used so we can send a change action
	var vCo 	= portalWnd.oUserProfile.getAttribute("company");
	var vJobCode 	= "110";

	//set object and table/prodline
	var empDMEObj 	= new DMEObject("JOBCODE", strPDL);

	//set an index
	empDMEObj.setIndex("JBCSET1&KEY=" + vCo + "=" + vJobCode);

	//tell it what fields to fetch
	empDMEObj.addField("EFFECTIVE-DATE");

	//prompt("obj",empDMEObj.toString());
	empDMEObj.execute();

	//grab a field from the dme result
	var vEffectDateHR06 = empDMEObj.getField("EFFECTIVE-DATE");	

	alert(vEffectDateHR06);
}

/************************************************************
	Function: getVarFromString

	Purpose:  get the variables from the search string

	Example:  var vCompany = getVarFromString("Company",parent.location.search);
************************************************************/
function getVarFromString(varName,str)
{
	str+='&'
	reStr="(?:\\&|\\?|^)" + varName + "=(.*?)(?:\\&|$)"
	var re=new RegExp(reStr,"gi")
	if(re.test(str))
		return RegExp.$1
	else
		return ""
}

/************************************************************
	Function: getDMEColumnIndex(pColumns)

	Purpose:  Helper Method used assist in getting DME record data as seen on pg 114 of 
		  Design Studio User Guide
************************************************************/
function getDMEColumnIndex(pColumns)
{
	var vIndex = new Array();
	for (var i=0; i<pColumns.length; i++)
	{
		var vLabel = pColumns[i].getAttribute("header").toUpperCase().split("_").join("-");
		vIndex[vLabel] = i;
	}
	return vIndex;
}

/************************************************************
	Function: getNodeValue(pNode)

	Purpose:  Helper Method used assist in getting DME field data as seen on pg 114 of
		  Design Studio User Guide
************************************************************/
function getNodeValue(pNode)
{
	for (var i=0; i<pNode.childNodes.length; i++)
	{
		if (pNode.childNodes[i].nodeType == 4)
		{
			return pNode.childNodes[i].nodeValue;
		}
	}
}

/************************************************************
	Function: DMEObject

	Purpose:  Constructor.  Return a new DMEObject for a file(table) and productline.
		  Initialize your instance variables.
************************************************************/
function DMEObject(pFile, pPDL)
{
	this.file = pFile;
	this.pdl = pPDL;
	this.index = "";
	this.conditions = "";
	this.fields = "";
	this.select = "";
	this.optParams= "";
	this.dmeString = "";
	this.records = null;
	this.columns = new Array();
	this.length = 0;
	this.maxRecords = 9999;
	this.success = false;
}

/************************************************************
	Function: setIndex(pIndex)

	Purpose:  Instance method for DMEObject.  Takes in a predefined index and sets in in 
		  the object..
************************************************************/
DMEObject.prototype.setIndex = function(pIndex)
{
	this.index = pIndex;

	return true;
}

/************************************************************
	Function: setIndex(pIndex)

	Purpose:  Instance method for DMEObject.  Takes in a predefined index and sets in in 
		  the object..
************************************************************/
DMEObject.prototype.setOptParams = function(pOptParams)
{
	this.optParams = pOptParams;

	return true;
}

/************************************************************
	Function: setConditions(pConditions)

	Purpose:  Instance method for DMEObject.  Takes in a predefined Conditions and sets in in 
		  the object..
************************************************************/
DMEObject.prototype.setConditions = function(pConditions)
{
	this.conditions = pConditions;

	return true;
}

/************************************************************
	Function: setSelect(pSelect)

	Purpose:  Instance method for DMEObject.  Takes in a predefined index and sets in in 
		  the object..
************************************************************/
DMEObject.prototype.setSelect = function(pSelect)
{
	this.select= pSelect;

	return true;
}

/************************************************************
	Function: addField(pField, pFieldValue)

	Purpose:  Instance method for DMEObject.  Takes in a field name and adds it to the 
		  fields portion of the DME string.
************************************************************/
DMEObject.prototype.addField = function(pField)
{
	this.fields += pField+";";

	return true;
}

/************************************************************
	Function: getField(pField)

	Purpose:  Instance method for DMEObject.  Takes in a field name as a parameter and 
		  return's it's value from the DME String.  If pRelRecTable is populated, pField
		  will be ignored and an array will be passed back.
************************************************************/
DMEObject.prototype.getField = function(pField, pRow, pRelRecTable)
{
	var rFieldValue;

	if ((pRow == undefined) ||
	    (pRow == null))
	{
		pRow = 0;
	}
	if ((pRelRecTable == undefined) ||
	    (pRelRecTable == null))
	{
		pRelRecTable = "";
	}

	//if it's not an empty string, we'll return the value from the related record tables
	if (pRelRecTable != "")
	{
		var vNewRelRecsArray = new Array();
		var vRelRecsArray = this.returnRecords[pRow].getElementsByTagName("RELRECS");
//alert(this.returnRecords[0].getElementsByTagName("RELRECS")[0].getElementsByTagName("RELREC")[1].getElementsByTagName("COL")[1].childNodes[0].nodeValue)
		//search each related table record set for one that matches pRelRecTable
		for(var i=0; i < vRelRecsArray.length; i++)
		{
			if (vRelRecsArray[i].getAttribute("name").toUpperCase().split("_").join("-") == pRelRecTable.toUpperCase())
			{
				var vRelRecArray = vRelRecsArray[i].getElementsByTagName("RELREC");
				//search specific related table record set's values
				for(var j=0; j < vRelRecArray.length; j++)
				{
					var vNewRelRecArray = new Array();
					var vRelRecColArray = vRelRecArray[j].getElementsByTagName("COL");

					for(var k=0; k < vRelRecColArray.length; k++)
					{
						var vRelRecColValue = vRelRecColArray[k].childNodes[0].nodeValue;
						vNewRelRecArray.push(vRelRecColValue);
					}
					vNewRelRecsArray.push(vNewRelRecArray)
				}

				break;
			}
		}
		rFieldValue = vNewRelRecsArray;
	}
	else
	{
		var vRecord = this.returnRecords[pRow].getElementsByTagName("COL");

		rFieldValue = getNodeValue(vRecord[this.columns[pField]]);
	}

	return (rFieldValue);
}

/************************************************************
	Function: BuildDMEString()

	Purpose:  Helper class method for DMEObject to build an DME string based on an DMEObject 
		  passed in.  Could be used stand-alone.
************************************************************/
DMEObject.BuildDMEString = function(vDMEObject)
{
	var vDMEString = portalWnd.DMEPath 
			 + "?PROD=" + vDMEObject.pdl
			 + "&FILE=" + vDMEObject.file
			 + "&INDEX=" + vDMEObject.index
			 + "&COND=" + vDMEObject.conditions
			 + "&FIELD=" + vDMEObject.fields
			 + "&SELECT=" + vDMEObject.select
			 + "&MAX=" + vDMEObject.maxRecords
			 + vDMEObject.optParams
			 +"&OUT=XML&DELIM="+(new Date()).getTime();

	//time was added to the unused field "DELIM" so it forces the DME to not used the cached data

	return vDMEString;
}

/************************************************************
	Function: execute()

	Purpose:  Instance method to execute this DME call.  Returns true on success, false on any 
		  failure
************************************************************/
DMEObject.prototype.execute = function()
{
	this.dmeString = DMEObject.BuildDMEString(this);

	//execute http post
	var vDMEInfo = portalWnd.httpRequest(this.dmeString);
	//if the status exists, there was an error in the system, otherwise proceed to pull data out
	if (vDMEInfo.status)
	{
		this.success = false;
	}
	else
	{
		var xmlObj = new portalWnd.DataStorage(vDMEInfo);
		this.returnRecords = xmlObj.document.getElementsByTagName("RECORD");
		this.columns = getDMEColumnIndex(xmlObj.document.getElementsByTagName("COLUMN"));
		this.length = this.returnRecords.length;
	}
	//return true if it was successful and false if it wasnt	
	return this.success;
}

/************************************************************
	Function: toString()

	Purpose:  Instance method to aid in debugging.  Returns the current DME string for the
		  the fields that have been added to the object so far.
************************************************************/
DMEObject.prototype.toString = function()
{
	this.dmeString = DMEObject.BuildDMEString(this);
	return this.dmeString;
}

 

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
	}																					

} }

 

 

 

GetCustomElementValue – Snippet for Smart Office Scripting

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

The following code can be used as a Snippet within the Lawson Smart Office Scripting Tool to retrieve the values for custom elements.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    /**
     * GetCustomElementValue - Returns the text value from a custom element
     * Parameters
     * sName        required    The custom element name
     *
     * Example:     GetCustomElementValue("myCustomElement")
    */
    private function GetCustomElementValue(sName)
    {
        var sRetVal     = "";
        var oTextBox    = form.GetCustomElement(sName);
 
        if (oTextBox != null)
        {
            sRetVal = oTextBox.Text;
        }
 
        return sRetVal;
    }
	/**
	 * GetCustomElementValue - Returns the text value from a custom element
	 * Parameters
	 * sName      	required	The custom element name
	 *
	 * Example:		GetCustomElementValue("myCustomElement")
	*/
	private function GetCustomElementValue(sName)
	{
		var sRetVal 	= "";
		var oTextBox 	= form.GetCustomElement(sName);

		if (oTextBox != null)
		{
			sRetVal = oTextBox.Text;
		}

		return sRetVal;
	}

Copy the code and save as GetCustomElementValue.jss, for example, or copy directly into the Script tool and Save Selection as Snippet.

 

Add Textbox – Snippet for Smart Office Scripting

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

The following code can be used as a Snippet within the Lawson Smart Office Scripting Tool to add new textboxes.

 

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
    /**
     * AddTextBox - Creates a textbox on the form
     * Parameters
     * sName        required    The unique textbox name
     * nRow         required    Numeric row to place the label  
     * nColumn      required    Numeric column to place the label
     * nColumnSpan  required    Numeric column span
     * bBrowse      required    Determines if the textbox should be a browse
     * oAddTo       required    Where to place label
     *  
     * Example:     AddTextBox("TestBox",1,20,10,false,formGrid)
    */
    private function AddTextBox(sName,nRow,nColumn,nColumnSpan,bBrowse,oAddTo)
    {
        if(nColumnSpan < 12){nColumnSpan = 12}      // Minumum to show full textbox
 
        var textbox1        = new TextBox();        // Create instance of textbox
        textbox1.Name       = sName;                // Assign a unique name
        textbox1.Height     = 11;                   // Set the height
 
        // Is this a browse type textbox
        if(bBrowse == true)
        {
            textbox1.Style    = StyleManager.StyleTextBoxBrowse;
        }
 
        Grid.SetRow(textbox1, nRow);                // Indicate the row             
        Grid.SetColumn(textbox1, nColumn);          // Indicate the column
        Grid.SetColumnSpan(textbox1, nColumnSpan);  // Indicate the column span
        form.AddCustomElement(oAddTo, textbox1);    // Where to place the textbox
    }
	/**
	 * AddTextBox - Creates a textbox on the form
	 * Parameters
	 * sName      	required	The unique textbox name
	 * nRow      	required	Numeric row to place the label	
	 * nColumn      required	Numeric column to place the label
	 * nColumnSpan  required	Numeric column span
	 * bBrowse     	required	Determines if the textbox should be a browse
	 * oAddTo		required	Where to place label
	 *	
	 * Example:		AddTextBox("TestBox",1,20,10,false,formGrid)
	*/
	private function AddTextBox(sName,nRow,nColumn,nColumnSpan,bBrowse,oAddTo)
	{
		if(nColumnSpan < 12){nColumnSpan = 12}		// Minumum to show full textbox

		var textbox1 		= new TextBox();		// Create instance of textbox
		textbox1.Name		= sName;				// Assign a unique name
		textbox1.Height 	= 11;					// Set the height

		// Is this a browse type textbox
		if(bBrowse == true)
		{
			textbox1.Style    = StyleManager.StyleTextBoxBrowse;
		}

		Grid.SetRow(textbox1, nRow);				// Indicate the row				
		Grid.SetColumn(textbox1, nColumn);			// Indicate the column
		Grid.SetColumnSpan(textbox1, nColumnSpan);	// Indicate the column span
		form.AddCustomElement(oAddTo, textbox1);	// Where to place the textbox
	}

Copy the code and save as AddTextbox.jss, for example, or copy directly into the Script tool and Save Selection as Snippet.

 

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

 

Add Label – Snippet for Smart Office Scripting

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

The following code can be used as a Snippet within the Lawson Smart Office Scripting Tool to add 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
    /**
     * 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
    }
	/**
	 * 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
	}

Copy the code and save as AddLabel.jss, for example, or copy directly into the Script tool and Save Selection as Snippet.