Session object is activated when user logs in to start a session. You can access to various methods and properties of session object in scripts. Use keyword of "session" as follow. 1.Operating Session Properties 2.Operating Tables 3.Operating Files 4.Operating System Control Tables 5.Calculating Date and Time 6.Calling Functions 7.Controling Progress Bar 8.Controling Dialogs 9.Operating Web Services Method to get ExcelFileOperator for an existing Excel file. Available methods of the object are as follow. -ExcelFileOperator#cloneSheet(int sheetIndex) Method to copy the specific sheet and add as the last sheet of the book. -ExcelFileOperator#setSheetNameAt(int sheetIndex, string value) Method to name the specific sheet. Note that some charactors(/\?*[]) should not included. -ExcelFileOperator#getLastRowIndex(int sheetIndex) Method to get an index of the last sheet of the book. -ExcelFileOperator#getValueAt(int sheetIndex, int rowIndex, int columnIndex) Method to get value of the cell specified with indexes. Note that indexed start from 0. -ExcelFileOperator#setValueAt(int sheetIndex, int rowIndex, int columnIndex, Object value) Method to set value at the specified cell. If operation succeeded, it returs true. If the cell is date formated, the value should be a string value like '2001/01/01' or '2001-01-01' or '20010101'. -ExcelFileOperator#removeRowAt(int sheetIndex, int rowIndex) Method to clear data and config at the specific row. -ExcelFileOperator#removeRowsBetween(int sheetIndex, int rowIndexFrom, int rowIndexThru) Method to clear data and config between the specific row numbers. -ExcelFileOperator#commit() Method to commit changes of the file. If succeeded it returns true. ////////// //Example// ////////// isOkay = session.copyFile('C:\\Test\\Book1.xlsx', 'C:\\Test\\Book2.xlsx'); if (isOkay) { operator = session.createExcelFileOperator('C:\\Test\\Book2.xlsx'); operator.setValueAt(0,1,0, 12345); //Numeric Cell at A2 operator.setValueAt(0,1,1, '2016-12-31'); //Date Cell at B2 operator.setValueAt(0,1,2, 'New string value'); //String Cell at C2 operator.commit(); session.browseFile('C:\\Test\\Book2.xlsx'); //Launching Excel } else { showMessage('Failed copying file'); } -TextFileOperator#getValueAt(int index) Method for 'Read' operation to get value of the column read at the index(the first is 0). Blank will be returned if the column at the index does not exist. -TextFileOperator#getColumnCount() Method for 'Read' operation to get count of columns read. -TextFileOperator#getRowIndex() Method for 'Read' operation to get index(the first is 0) of the row where cursor placed. -TextFileOperator#next() Method for 'Read' operation to put cursor at the next row. If the next row exists, it returns true. -TextFileOperator#previous() Method for 'Read' operation to put cursor at the previous row. If the previous row exists, it returns true. -TextFileOperator#addValue(Object value) Method for 'Write' operation to add value of the next column to the array. It returns index of the column added. -TextFileOperator#addRow() Method for 'Write' operation to add a row with the column values array. It returns index of the row added and the array is cleared then. Note that rows are not written until executed. -TextFileOperator#execute() Method to execute Read/Write operation to return count of rows processed. This will be implicitly executed in the first next() operation. -TextFileOperator#resetCursor() Method to reset cursor position. Note that next() is required to get column values. TABLEID_FIELDID.value = session.getOffsetDate(...) + ''; TABLEID_FIELDID.value = session.timeStamp + ''; TABLEID_FIELDID.value = session.thisMonth + ''; TABLEID_FIELDID.value = session.today + ''; *1.The first month of fiscal year. For example, 4 represents April. If not registered with the key in system variant table, its value is assumed to be 1. *2.The last day of the fiscal year. 31 means the last day of each month. If not registered with the key in system variant table, its value is assumed to be 31. *3.For example, if the value is 201611, it means the 11th month of the fiscal year of 2016 is the past limit one can input account data. var dialog = session.getOptionDialog(); dialog.addOption('Value of OPTION as 1'); // reply:0 // dialog.addOption('Value of OPTION as 2'); // reply:1 // dialog.addOption('Close'); // reply:2 // dialog.setWidth(300); var reply = dialog.request('Choose an Option'); if (reply == 0) { instance.parmMap.put('OPTION', '1'); instance.callFunction('FNCTION1'); } if (reply == 1) { instance.parmMap.put('OPTION', '2'); instance.callFunction('FNCTION1'); } if (reply == 2 || reply == -1) { instance.returnMap.put('RETURN_MESSAGE', '*Processing Canceled.'); } InputDialog#addField(String caption, String inputType, int area, String parmID) - Method to add a field to get Field object. InputType is either of ALPHA, ZEROFILL, KANJI, NUMERIC, DATE, LISTBOX, CHECKBOX, TEXTAREA. Area is either of 0(top), 1(center), -1(not visible). ParmID is omittable which is to link to the parameter mentioned later. InputDialog#request(String title) - Method to show dialog with the title specified. InputDialog#setMessage(String message) - Method to set the message on dialog. InputDialog#setMessageHeight(int height) - Method to set height of message area explicitly(default is 55). InputDialog#setWidth(int width) - Method to set width of dialog explicitly(default is 300). Width may be extended automatically according to the width of field added. Methods for Field object gotten by addField(...) are as follow. Field#setEditable(boolean editable) - Method to set if the field is editable or not. Field#isEditable() - Method to get if the field is editable or not. Field#getParmID() - Method to get ParmID. Field#setSize(int digits) - Method to set field length valid for types of ALPHA, ZEROFILL, KANJI, NUMERIC. Field#setDecimal(int decimals) - Method to set decimal length of NUMERIC field. Note that setSize(...) is to set length of integer for Numeric field. Field#setValue(Object value) - Method to set value at the field. Field#getValue() - Method to get field value. Field#addItem(String externalValue, Object internalValue) - Method to add an item for LISTBOX fields. ExternalValue is how it is shown on the list. Use getValue() to get internalValue of selected item and use getItem() to get externalValue of selected item. Field#getItemCount() - Method to get count of items in a LISTBOX field. Field#setPrompter(String prompterID, String parmIDsPuttingFrom, String parmIDsPuttingInto, String parmIDsGettingFrom, String parmIDsGettingInto) - Method to set prompter for field type of ALPHA, ZEROFILL and NUMERIC. ParmIDs are separated by ';'. Field#setFileChooser(String title, String fileExtentions, String initialDirectory) - Method to set file chooser for type of ALPHA field. File extentions are separated by ';'. If initial directory is omited, file path value specified by setValue() is set implicitly. Field#setDirectoryChooser(String title, String initialDirectory) - Method to set file chooser for type of ALPHA field. If initial directory is omited, file path value specified by setValue() is set implicitly. Field#setComment(String text) - Method to set comment at right side of the field. Following is an example with codes. On the dialog users type tab-key to transfer focus and Enter or OK to execute. // Dialog Definition // var dialog = session.getInputDialog(); dialog.setMessage('*Specify settings for BOM explosion.'); dialog.setWidth(400); // Item Number // var nrItem = dialog.addField('Item Number', 'ALPHA', 0, 'NRITEM'); nrItem.setEditable(false); nrItem.setSize(15); nrItem.setValue(instance.parmMap.get('NRITEM')); // Feature Option Code // var cdFopt = dialog.addField('F/O Code', 'ALPHA', 0, 'CDFOPT'); cdFopt.setSize(10); cdFopt.setPrompter('BF200', 'NRITEM;CDFOPT', 'NRITEM;CDFOPT', 'CDFOPT','CDFOPT'); // Target Date for Explosion // var dtExplosion = dialog.addField('Target Date', 'DATE', 0); // Unit Quantity // var qtExplosion = dialog.addField('Unit Quantity', 'NUMERIC', 1); qtExplosion.setValue(1); qtExplosion.setSize(7); // Explosion Type // var kbExplosion = dialog.addField('Explosion Type', 'LISTBOX', 1); kbExplosion.addItem('Single Level', '1'); kbExplosion.addItem('Structures', '2'); kbExplosion.addItem('Summary', '3'); // Pass-Thru // var fgPassthru = dialog.addField('Pass-Thru', 'CHECKBOX', 1); fgPassthru.setValue(true); // Showing dialog to request answers // var reply = dialog.request('Settings for BOM Explosion'); if (reply == 0) { if (fgPassthru.value == true) { ... } else { ... } } else { instance.returnMap.put('RETURN_MESSAGE', '*Processing canceled.'); } CheckListDialog#addRow(String keyValue, String expression, boolean isSelected) - Method to add a row in dialog. CheckListDialog#sortList(boolean isSotedAscend) - Method to sort rows according to expressions. if parameter ommitted, it will be sorted ascend. if false specified, it will be sorted descend. CheckListDialog#setWidth(int width) - Method to set width of dialog. CheckListDialog#request(String title) - Method to show dialog with the title specified. CheckListDialog#setListSelected(String keyList) - Method to set specific rows selected with key values. Values are separated by ';'. CheckListDialog#getListSelected() - Method to get list of key values selected on dialog. Values are separated by ';'. CheckListDialog#isSelected(String KeyValue) - Method to get if a specific row with key value is selected or not. Following is an example with codes. This function is defined as XF000 and it is linked as a prompter of criteria field of XF100,110,300 and checked values work as OR conditions. Exchange parameters for the prompter are all 'JT010.STORDER'. // Dialog Definition // var dialog = session.getCheckListDialog(); dialog.addRow('10', 'Opened'); dialog.addRow('20', 'Issued'); dialog.addRow('30', 'Dispatched'); dialog.addRow('40', 'Closed'); dialog.setListSelected(instance.parmMap.get('JT010.STORDER')); // Display Dialog to Request Checking List // var reply = dialog.request('Checking Order Status'); if (reply == 0) { instance.returnMap.put('JT010.STORDER', dialog.getListSelected()); } Method to get digested value of the value specified according to the algorithm specified. Typically used to process password for vendor/customer to login EDI module. Available algorithms are MD5, SHA-1, SHA-256, SHA-384, SHA-512 etc.(Refer to java.security.MessageDigest). It returns blank value if algorithm specified is invalid. If last 2 parameters omitted, those values 1 and '' are applied respectedlly. If last 3 parameters omitted, "Hash Format" of the system will be appllied. Method to get random string with specified length and characters. Used to reset password value. Method to send GET-Request(*4) as uri specified to receive Response(*5). Encoding is omittable(default is UTF-8). Method to get POST-Request object for the WEB-service-uri specified. Encoding is omittable(default is UTF-8). Available methods of Request object are as follow. Request#setParameter(String name, String value) - Method to set value to the parameter specified by name. Request#setHeader(String name, String value) - Method to set value to the header specified by name. Request#execute() - Method to send POST-Request to receive Response(*5). Method to parse text data in XML format to get XML dokument. Encoding is omittable(default is UTF-8). Method to transform XML document to plain text. Useful for testing. Method to get XML document which root tag is the name specified. Name is omittable. Method to add a node with the tag name specified to the XML document. Notice that even you can add a node but you can not put the node in specific position. You need to do like existingNode.appendChild(newNode) to put newNode as a child node of existingNode. Method to get XML node with the tag name specified from the node(or XML document). If multiple nodes exist with the tag name, the first node in position will be selected. Use method of node.getAttribute(name) to get attribute value of the node and node.setAttribute(name, value) to set value to the specific attribute of the node. And use node.setTextContent(value) to set text content value at the specific node. Method to get XML node list with the tag name specified from the node(or XML document). Use nodelist.get(index) to get specific node at the index of nodelist. And use nodelist.size() to get count of nodes on nodelist. Method to get text content with the tag name specified from the node(or XML document). Method to create and get JSON object with text specified. Text value is omittable and it should be in JSON format which means it looks like {...}. Method to create and get JSON array with text specified. Text value should be in JSON array format which means it looks like [...]. Method to get a JSON array with the name of key. Method to get a JSON object with key from specified JSON object. Use object.getString(key) to get string value of specific key from the object. Use object.getInt(key) to get integer value. And use object.put(key, value) to put value to specific key of the object. Method to get a JSON object at the index of the JSON array. *4.GET-request is coded in uri to be sent. And POST-request is created as an object to be sent. If you have multiple parameters for your request, you had better use POST-request. *5.As response itself is a plain-text value, you need to parse it as XML document or JSON object to process. Following is a sample coding. This is a script to communicate with web-service to get address by Japanese ZIP number. It send a GET request to receive response to parse it as XML document. // Variants Definition // var reply = 0; var dialog = session.getInputDialog(); var reply; var nrYubin = dialog.addField('ZIP Number', 'ALPHA', 0); nrYubin.setSize(8); var txJyusyo = dialog.addField('Address', 'ALPHA', 0); txJyusyo.setSize(50); txJyusyo.setEditable(false); dialog.setMessage('Input ZIP number to get address. This is driven by the web-service zip.cgis.biz.'); // Show Dialog to Request // for (;;) { reply = dialog.request('Using a WEB-Service'); if (reply == 0) { var value = nrYubin.value.replace('-', ''); var uri = 'http://zip.cgis.biz/xml/zip.php?zn=' + value; var response = session.requestWebService(uri); var document = session.parseStringToGetXmlDocument(response); var rootNode = session.getXmlNode(document, 'ZIP_result'); var nodeList = session.getXmlNodeList(rootNode, 'value'); if (nodeList == null || nodeList.size() < 7) { dialog.setMessage('ZIP Number is invalid.'); } else { var stateText = nodeList.get(4).getAttribute('state'); var cityText = nodeList.get(5).getAttribute('city'); var addressText = nodeList.get(6).getAttribute('address'); txJyusyo.value = stateText + ' ' + cityText + ' ' + addressText; dialog.setMessage('Address is successfully scanned.'); } } else { break; } } Notice that this is a sample to use an existing web-service. Refer to Publishing WEB-Service to create your own web-services. |