The following example utilizes Smart Office scripting to hook into the AfterTransaction event to display the corresponding Vendor balance. Not a very complicated script. Basically a new label added to the header of the form and a custom Data Query function to gather values from the form and fetch the balance, which is then sent to the new label.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | //----------------------------------------------------------------------------- // JScript Example // Created by: Josh Geving - Innovations Group // // Description: Example script to fetch a vendor balance from APVENBAL // // Notice: VBASET2 is being used as the index which is Vendor Group // and Vendor, depending on yous situation you may choose to // change the code below and use VBASET1 which includes // Company // // // Last Tested on Smart Office Version 10.1.0.38 //----------------------------------------------------------------------------- import System; import System.Windows; import System.Windows.Controls; import S3.Client.Forms; package S3.Client.Forms.JScript { class JjgAp10Balance { var console, form, formGrid; public function Init(element: Object, args: Object, controller: Object, debug: Object) { try { form = controller; formGrid = form.FormGrid; console = debug; // TODO Add your code here // add a lable to display the vendor balance var label = ControlsUtil.AddCustomLabel(form, formGrid, "lblBalance", 1, 60, 10, ""); // hook into the AfterTransaction event form.add_AfterTransaction(OnAfterTransaction); form.add_BeforeUnload(OnBeforeUnload); } catch (e) { console.WriteLine(ScriptUtil.FormatException("Init", e)); } } // event handlers public function OnBeforeUnload(sender: Object, e: FormEventArgs) { // perform cleanup // remove the hook for AfterTransaction form.remove_AfterTransaction(OnAfterTransaction); form.remove_BeforeUnload(OnBeforeUnload); } // AfterTransaction Event public function OnAfterTransaction(sender: Object, e: TransactionEventArgs) { // variable for balance var vBalance = RunDataMine(); // set the value of the custom label to the balance found form.SetCustomElementValue("lblBalance", vBalance); } private function RunDataMine() { //OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL; //gather form variables from the transaction var vVendorGroup = form.GetTransactionValue("VEN-VENDOR-GROUP"); var vVendor = form.GetTransactionValue("VEN-VENDOR").Trim(); // build up the Data Service call var sProd = form.GetUserAttribute("productline"); var sFile = "APVENBAL"; var sField = "CURRENT-BAL"; var sIndex = "VBASET2&KEY="+vVendorGroup+"="+vVendor+""; var sCond = ""; var sSelect = ""; var sMax = ""; // Pass the variables for the API to DataService_Execute var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax); console.WriteLine("aDataAPI.length: " + aDataAPI.length); // Did we get anything back from the call? if(aDataAPI.length > 0) { var i = 0; for(i = 0; i < aDataAPI.length; i++) { console.WriteLine(aDataAPI[i]); return aDataAPI[i]; } } else{ console.WriteLine("***No Records***"); return "No Balance"; } } // private functions /** * DataService_Execute - This method returns an array for the api specified * Detail description * This method returns an array of values for for the api details * @param required sProd, PROD, defaults to user profile if not set - required * @param required sFile, FILE * @param required sField, FIELD * @param optional sIndex, INDEX, removed from api if not set * @param optional sCond, COND * @param optional sSelect, SELECT * @param optional sMax, MAX, defaults to 0 if not set * @access private * @return array * * Example: * * private function RunDataMine() { //OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL; //gather form variables from the transaction var vVendorGroup = form.GetTransactionValue("VEN-VENDOR-GROUP"); var vVendor = form.GetTransactionValue("VEN-VENDOR").Trim(); // build up the Data Service call var sProd = form.GetUserAttribute("productline"); var sFile = "APVENBAL"; var sField = "CURRENT-BAL"; var sIndex = "VBASET2&KEY="+vVendorGroup+"="+vVendor+""; var sCond = ""; var sSelect = ""; var sMax = ""; // Pass the variables for the API to DataService_Execute var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax); console.WriteLine("aDataAPI.length: " + aDataAPI.length); // Did we get anything back from the call? if(aDataAPI.length > 0) { var i = 0; for(i = 0; i < aDataAPI.length; i++) { console.WriteLine(aDataAPI[i]); return aDataAPI[i]; } } else{ console.WriteLine("***No Records***"); return "No Balance"; } } */ private function DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax) { var a = new Array(); var aFields = new Array(); var i = 0; var s = ""; var oXML; var oRecs; var oRecNum; var oRec; var oFields; // Productline sProd empty, set from profile if(sProd == ""){sProd = form.GetUserAttribute("productline");} // Max sMax empty, set to 0 for all if(sMax == ""){sMax = 0;} // Build the complete Data Service Call s = ScriptConstants.DataMinePath + "?PROD=" + sProd + "&FILE=" + sFile + "&FIELD=" + sField; // If Index we add Index to the call if(sIndex != ""){s += "&INDEX=" + sIndex;} // The rest of the call s += "&COND=" + sCond + "&SELECT=" + sSelect + "&MAX=" + sMax + "&OUT=XML&DELIM="+ new Date().getTime(); // Time used to prevent caching console.WriteLine("s: " + s); // Make the server request, record the time it took var bTime = new Date().getTime(); oXML = ScriptUtil.ServerRequest(s); var eTime = new Date().getTime(); console.WriteLine("API Execution Time: " + (eTime-bTime)/1000 + "seconds"); // Get the Record Count Node oRecs = oXML.SelectSingleNode("//RECORDS"); oRecNum = oRecs != null ? oRecs.ChildNodes.Count : 0; console.WriteLine("oRecNum: " +oRecNum); // Determine if records were returned if(oRecNum == 0) { console.WriteLine("Data Service Call\n\n" + s + "\n\n returned " + oRecNum + " records."); return a; } // Build an array with the results for(oRec in oRecs.ChildNodes) { oFields = oRec.SelectSingleNode("./COLS"); aFields = new Array(); for(i = 0; i < oFields.ChildNodes.Count; i++) { aFields[aFields.length] = oFields.ChildNodes[i].InnerText; } a[a.length] = aFields; } return a; } } } |
//-----------------------------------------------------------------------------
// JScript Example
// Created by: Josh Geving - Innovations Group
//
// Description: Example script to fetch a vendor balance from APVENBAL
//
// Notice: VBASET2 is being used as the index which is Vendor Group
// and Vendor, depending on yous situation you may choose to
// change the code below and use VBASET1 which includes
// Company
//
//
// Last Tested on Smart Office Version 10.1.0.38
//-----------------------------------------------------------------------------
import System;
import System.Windows;
import System.Windows.Controls;
import S3.Client.Forms;
package S3.Client.Forms.JScript {
class JjgAp10Balance
{
var console, form, formGrid;
public function Init(element: Object, args: Object, controller: Object, debug: Object)
{
try {
form = controller;
formGrid = form.FormGrid;
console = debug;
// TODO Add your code here
// add a lable to display the vendor balance
var label = ControlsUtil.AddCustomLabel(form, formGrid, "lblBalance", 1, 60, 10, "");
// hook into the AfterTransaction event
form.add_AfterTransaction(OnAfterTransaction);
form.add_BeforeUnload(OnBeforeUnload);
} catch (e) {
console.WriteLine(ScriptUtil.FormatException("Init", e));
}
}
// event handlers
public function OnBeforeUnload(sender: Object, e: FormEventArgs)
{
// perform cleanup
// remove the hook for AfterTransaction
form.remove_AfterTransaction(OnAfterTransaction);
form.remove_BeforeUnload(OnBeforeUnload);
}
// AfterTransaction Event
public function OnAfterTransaction(sender: Object, e: TransactionEventArgs)
{
// variable for balance
var vBalance = RunDataMine();
// set the value of the custom label to the balance found
form.SetCustomElementValue("lblBalance", vBalance);
}
private function RunDataMine()
{
//OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL;
//gather form variables from the transaction
var vVendorGroup = form.GetTransactionValue("VEN-VENDOR-GROUP");
var vVendor = form.GetTransactionValue("VEN-VENDOR").Trim();
// build up the Data Service call
var sProd = form.GetUserAttribute("productline");
var sFile = "APVENBAL";
var sField = "CURRENT-BAL";
var sIndex = "VBASET2&KEY="+vVendorGroup+"="+vVendor+"";
var sCond = "";
var sSelect = "";
var sMax = "";
// Pass the variables for the API to DataService_Execute
var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax);
console.WriteLine("aDataAPI.length: " + aDataAPI.length);
// Did we get anything back from the call?
if(aDataAPI.length > 0)
{
var i = 0;
for(i = 0; i < aDataAPI.length; i++)
{
console.WriteLine(aDataAPI[i]);
return aDataAPI[i];
}
}
else{
console.WriteLine("***No Records***");
return "No Balance";
}
}
// private functions
/**
* DataService_Execute - This method returns an array for the api specified
* Detail description
* This method returns an array of values for for the api details
* @param required sProd, PROD, defaults to user profile if not set - required
* @param required sFile, FILE
* @param required sField, FIELD
* @param optional sIndex, INDEX, removed from api if not set
* @param optional sCond, COND
* @param optional sSelect, SELECT
* @param optional sMax, MAX, defaults to 0 if not set
* @access private
* @return array
*
* Example:
*
*
private function RunDataMine()
{
//OUT=XML&MAX=100&PROD=APPS901&FILE=APVENBAL&INDEX=VBASET2&KEY=1=1&FIELD=CURRENT-BAL;
//gather form variables from the transaction
var vVendorGroup = form.GetTransactionValue("VEN-VENDOR-GROUP");
var vVendor = form.GetTransactionValue("VEN-VENDOR").Trim();
// build up the Data Service call
var sProd = form.GetUserAttribute("productline");
var sFile = "APVENBAL";
var sField = "CURRENT-BAL";
var sIndex = "VBASET2&KEY="+vVendorGroup+"="+vVendor+"";
var sCond = "";
var sSelect = "";
var sMax = "";
// Pass the variables for the API to DataService_Execute
var aDataAPI = DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax);
console.WriteLine("aDataAPI.length: " + aDataAPI.length);
// Did we get anything back from the call?
if(aDataAPI.length > 0)
{
var i = 0;
for(i = 0; i < aDataAPI.length; i++)
{
console.WriteLine(aDataAPI[i]);
return aDataAPI[i];
}
}
else{
console.WriteLine("***No Records***");
return "No Balance";
}
}
*/
private function DataService_Execute(sProd,sFile, sField, sIndex, sCond, sSelect, sMax)
{
var a = new Array();
var aFields = new Array();
var i = 0;
var s = "";
var oXML;
var oRecs;
var oRecNum;
var oRec;
var oFields;
// Productline sProd empty, set from profile
if(sProd == ""){sProd = form.GetUserAttribute("productline");}
// Max sMax empty, set to 0 for all
if(sMax == ""){sMax = 0;}
// Build the complete Data Service Call
s = ScriptConstants.DataMinePath + "?PROD=" + sProd + "&FILE=" + sFile + "&FIELD=" + sField;
// If Index we add Index to the call
if(sIndex != ""){s += "&INDEX=" + sIndex;}
// The rest of the call
s += "&COND=" + sCond + "&SELECT=" + sSelect + "&MAX=" + sMax +
"&OUT=XML&DELIM="+ new Date().getTime(); // Time used to prevent caching
console.WriteLine("s: " + s);
// Make the server request, record the time it took
var bTime = new Date().getTime();
oXML = ScriptUtil.ServerRequest(s);
var eTime = new Date().getTime();
console.WriteLine("API Execution Time: " + (eTime-bTime)/1000 + "seconds");
// Get the Record Count Node
oRecs = oXML.SelectSingleNode("//RECORDS");
oRecNum = oRecs != null ? oRecs.ChildNodes.Count : 0;
console.WriteLine("oRecNum: " +oRecNum);
// Determine if records were returned
if(oRecNum == 0)
{
console.WriteLine("Data Service Call\n\n" + s + "\n\n returned " + oRecNum + " records.");
return a;
}
// Build an array with the results
for(oRec in oRecs.ChildNodes)
{
oFields = oRec.SelectSingleNode("./COLS");
aFields = new Array();
for(i = 0; i < oFields.ChildNodes.Count; i++)
{
aFields[aFields.length] = oFields.ChildNodes[i].InnerText;
}
a[a.length] = aFields;
}
return a;
}
} }







