fonctions de soutien
Ce script de démarrage CCDS doit être modifié par un développeurs JavaScript pour votre cas d’utilisation. Il ne fonctionnera pas sans modification.
Enregistrez le bloc de codes ci-dessous en tant que script dans votre CCDS Intacct Sage et nommez-le soutienFunctions.
function logContentDetails(content, contentName, limit) { /** * a utlility function - returns an array of the start and end to substring the content so that we can log * all of it in 1000-byte chunks (the max size of a verbose log detail) * so, for example, in the case of a 2025 length string this would return: * [ {start: 0, end: 1000}, * {start: 1000, end: 2000}, * {start: 2000, end: 2025} ] * @param {} content */ function getChunksToLog(content) { var bytesRemaining = content.length; var array = []; var startByte = 0; var endByte = 0; const maxDetailSize = 1000; while (bytesRemaining > 0) { endByte = Math.min(bytesRemaining, maxDetailSize); array.push({ start: startByte, end: startByte + endByte }); startByte += endByte; bytesRemaining -= maxDetailSize; } return array; } var ChunksToLogArray = getChunksToLog(content); var limitUse = limit ? limit : ChunksToLogArray.length; if (limitUse > ChunksToLogArray.length) { limitUse = ChunksToLogArray.length; } for (var chunkIndexer = 0; chunkIndexer < limitUse; chunkIndexer++) { var chunkIdentifier = chunkIndexer + 1; // humans like to see number sequences that start with 1 // to make sorting the log file easier, let's make each 'chunk' a 3-digit value with leading zeroes as necessary var chunkIdentifierPadded = '' + chunkIdentifier; if (chunkIdentifier < 10) { chunkIdentifierPadded = '00' + chunkIdentifier; } else if (chunkIdentifier < 100) { chunkIdentifierPadded = '0' + chunkIdentifier; } ai.log.logVerbose(contentName + ' ' + chunkIdentifierPadded, content.substring(ChunksToLogArray[chunkIndexer].start, ChunksToLogArray[chunkIndexer].end)); sleepX(2000); // to avoid excessive logging } } function sleepX(milliSeconds) { //NOTE this should be replaced by non-CPU consuming sleep function, expected in 2024R2 var startTime = new Date().getTime(); // get the current time while (new Date().getTime() < startTime + milliSeconds); } function getintacctRequestParms(dataSource) { //get various settings for making Intacct requests var intacctRequestParms = {}; intacctRequestParms.userID = dataSource.getSetting('Intacct UserID').getValue(); intacctRequestParms.userPassword = dataSource.getSetting('Intacct Password').getValue(); intacctRequestParms.companyId = dataSource.getSetting('Company ID').getValue(); intacctRequestParms.senderId = dataSource.getSetting('Sender ID').getValue(); intacctRequestParms.senderPassword = dataSource.getSetting('Sender Password').getValue(); intacctRequestParms.clientId = dataSource.getSetting('Client Id').getValue(); intacctRequestParms.locationId = dataSource.getSetting('Location Id').getValue(); //TODO needed? intacctRequestParms.includeNonPostingDimensions = dataSource.getSetting('Include non-posting dimensions').getValue(); intacctRequestParms.control_controlid = 'ADAP' + (new Date()).getTime().toString(); intacctRequestParms.control_uniqueid = 'false'; intacctRequestParms.control_dtdversion = '3.0'; return intacctRequestParms; } function getintacctGLRequestParms(dataSource) { //get various settings for making GL Data extract requests var intacctGLRequestParms = {}; intacctGLRequestParms.reportingBooks = dataSource.getSetting('Reporting Books (comma separated)').getValue(); //reporting books to process intacctGLRequestParms.intacctDimensions = dataSource.getSetting('Intacct Dimensions (comma separated)').getValue(); //dimensions to split data by intacctGLRequestParms.userDefinedDimensions = dataSource.getSetting('User Defined Dimensions (comma separated)').getValue(); //user defined dimensions to include return intacctGLRequestParms; } function getColumnRemoteIds(rowset) { var columnIds = []; var columns = rowset.getColumns(); for (var i=0; i<columns.length; i++) { var id = columns[i].getId(); columnIds.push(id); } return columnIds; } //end getColumnRemoteIds function getReportingPeriodsToImportXXX(periodRange) { /*** * * This version uses Intacct Reporting Periods to determing the periods * This version is not in use, preserved here in case it turned out to be useful elsewhere * * get the specified period range info for the GL balances import * * Get the period range from the user's period range paramater * Construct start and end date strings MM/DD/YYYY (Intacct's format) * Set the end date to the last day of the last month in the range rather than the first day of the following month from the Adaptive period range * Pull the reporting periods from Intacct * Find the starting and ending reporting periods that correspond to the Adaptive periods * Build an array containing all the Reporting Periods from start to end of the requested range * ***/ var rowsremaining; var reportingPeriodMap = []; //for mapping calendar dates to Intacct reporting periods var periodRangeStartSetting = periodRange.getValue().getFromPeriodStartDateTime(); var periodRangeEndSetting = periodRange.getValue().getToPeriodEndDateTime(); //extract start and end dates into strings formatted MM/DD/YYYY //these will be used to lookup the associated reporting periods from Intacct let mo, dy, yr; //temporary holders mo = periodRangeStartSetting.substring(5,7); dy = '01'; yr = periodRangeStartSetting.substring(0,4); //start period date in MM/DD/YYYY format var extractPeriodRangeStartDate = mo + '/' + dy + '/' + yr; //end date from Adaptive is midnight of the next day, so have to back up one day to get correct period value periodRangeEndTemp = new Date(periodRangeEndSetting); periodRangeEndTemp = new Date(periodRangeEndTemp.setDate(periodRangeEndTemp.getDate() - 1)); //subtract one day yr = periodRangeEndTemp.getFullYear().toString(); mo = (periodRangeEndTemp.getMonth() + 1); //month is zero based //period is 2 digits, left padded with zero let pad = ''; if (mo < 10) { pad = '0'; } mo = pad + mo.toString(); //month, with 0 pad if needed dy = periodRangeEndTemp.getDate(); //day, no zero pad needed //end period date in MM/DD/YYYY format var extractPeriodRangeEndDate = mo + '/' + dy + '/' + yr; /*** * * Build the table of reporting period dates from Intacct * ***/ var reportingPeriodTableName = 'REPORTINGPERIOD'; var reportingPeriodColumns = 'NAME,HEADER1,HEADER2,START_DATE,END_DATE,STATUS'; rowsremaining = -1; //initial condition while(rowsremaining !== 0) { response = intacctReadByQueryRequest(reportingPeriodTableName,reportingPeriodColumns,intacctRequestParms,maxRows,operation_sessionid,intacctURL,rowsremaining); if (!response) throw('Getting Reporting Period data from Intacct failed. See log for additional messages'); //set variables from response rows = response.rows; rowsremaining = response.rowsremaining; if (response.operation_sessionid !== undefined) operation_sessionid = response.operation_sessionid; if (response.intacctURL !== undefined) intacctURL = response.intacctURL; reportingPeriodMap = updateReportingPeriodMap(rows); } /*** * * Compute the reporting periods cooresponding to the user's requested period range * * One important assumption is Intacct periods align exactly with Adaptive periods * * Extract the reporting period from the map. The map structure is: * reportingPeriodMap[index] = {periodName: periodName, startDate: startDate, endDate: endDate} * ***/ //iterate over reportingPeriodMap to find start and end Intacct periods let startDateIdx = -1, endDateIdx = -1; for (let j=0; j<reportingPeriodMap.length; j++) { if(reportingPeriodMap[j].startDate == extractPeriodRangeStartDate ) startDateIdx = j; if(reportingPeriodMap[j].endDate == extractPeriodRangeEndDate ) endDateIdx = j; } if (startDateIdx == -1) throw('An Intacct Reporting Period that begins ' + extractPeriodRangeStartDate + ' was not found'); if (endDateIdx == -1) throw('An Intacct Reporting Period that ends ' + extractPeriodRangeEndDate + ' was not found'); /** * * Set up reportingPeriodsToImport array of reporting periods to be exported * * reportingPeriodsToImport => Array of {periodName: periodName, startDate: startDate, endDate: endDate} * we need the name for the Intacct request, and date for loading into staging * * ***/ var reportingPeriodsToImport = reportingPeriodMap.slice(startDateIdx,endDateIdx + 1); return reportingPeriodsToImport; } //end getReportingPeriodsToImportXXX