UXDE dot Net Wordpress Themes

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

} }

 

Leave a Reply

You must be logged in to post a comment.