├── AJAXFunctions.ts ├── statecountries.js ├── statecountries.ts ├── calcNSWBusinessDays.js ├── AJAXFunctionsTS.d.ts ├── AJAXFunctions.d.ts ├── simpleBatch.d.ts ├── batchProcess.d.ts ├── statecountries.d.ts ├── LICENSE ├── exposeItemTemplate.ts ├── README.md ├── exposeItemTemplate.js ├── AJAXFunctions.js ├── kotnMergeTemplate.js ├── simpleBatch.ts ├── simpleBatch.js ├── batchProcess.ts ├── batchProcess.js ├── calculateShippingDates.js ├── exposeImageNames.ts ├── exposeImageNames.js └── SuiteScriptAPITS.d.ts /AJAXFunctions.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BKnights/KotN-Netsuite/HEAD/AJAXFunctions.ts -------------------------------------------------------------------------------- /statecountries.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BKnights/KotN-Netsuite/HEAD/statecountries.js -------------------------------------------------------------------------------- /statecountries.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BKnights/KotN-Netsuite/HEAD/statecountries.ts -------------------------------------------------------------------------------- /calcNSWBusinessDays.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BKnights/KotN-Netsuite/HEAD/calcNSWBusinessDays.js -------------------------------------------------------------------------------- /AJAXFunctionsTS.d.ts: -------------------------------------------------------------------------------- 1 | declare module KOTNUtil { 2 | export function sendJSResponse(request: nlobjRequest, response: nlobjResponse, respObject: any): void; 3 | export function unique(arr): any[]; 4 | export function toJSON(target): string; 5 | } 6 | -------------------------------------------------------------------------------- /AJAXFunctions.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | module KOTNUtil { 3 | function sendJSResponse(request: nlobjRequest, response: nlobjResponse, respObject: Object): void; 4 | function unique(arr): any[]; 5 | function toJSON(target): string; 6 | } 7 | -------------------------------------------------------------------------------- /simpleBatch.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare function simpleBatch(arr: any[], proc: (t: any, idx: number, a: any[]) => void, reserve?: number, maxMinutes?: number): void; 3 | declare function dynamicBatch(arr: any[], proc: (t: any) => void, reserve?: number, maxMinutes?: number): void; 4 | -------------------------------------------------------------------------------- /batchProcess.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | interface JobContext { 3 | getTargetsUsage: () => number; 4 | getMaxUsage: () => number; 5 | } 6 | declare function batchProcess(getContext: (ctx: JobContext) => JobContext, getTargets: (ctx: JobContext, isRerunCheck: boolean) => Object[], processTarget: (ctx: JobContext, simpleArg?: any) => boolean, rerunParams: (ctx: JobContext) => void): void; 7 | -------------------------------------------------------------------------------- /statecountries.d.ts: -------------------------------------------------------------------------------- 1 | module statecountries { 2 | export var stateList: { id: string; c: string; sn: string; fn: string; }[]; 3 | export var countryList: { fn: string; id: number; }[]; 4 | export function getCountriesWithStates(): any[]; 5 | export function getStates(countryCode); 6 | export function getStateId(countryCode, stateCode): string; 7 | export function getStateCodeById(id): string; 8 | export function getStateListByCountryId(id); 9 | export function getCountryCodeById(id, fallbackToName?: bool): string; 10 | } 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 BKnights 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /exposeItemTemplate.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module kotnShadowItemTemplate{ 4 | 5 | /** 6 | * copy store template item to field available in searches 7 | * @param {string} type event type 8 | * @return {void} 9 | */ 10 | export function itemBeforeSubmit(type) { 11 | if (type == 'edit' || type == 'create') { 12 | var tmplt = nlapiGetFieldText('storeitemtemplate'); 13 | var shadow = nlapiGetFieldValue('custitem_kotn_shadow_template'); 14 | if (tmplt != shadow) nlapiSetFieldValue('custitem_kotn_shadow_template', tmplt); 15 | } 16 | } 17 | 18 | /** 19 | * expose the item template after bundle install. You'll need a deployment 20 | * for each type of item. e.g., Inventory Item, Non-Inventory Item, Serialized Item 21 | * @param {string} recType Record type supplied by the mass update runner 22 | * @param {string|number} recId Item internal id supplied by the mass update runner 23 | */ 24 | export function massShadow(recType, recId) { 25 | var item = nlapiLoadRecord(recType, recId); 26 | var tmplt = item.getFieldText('storeitemtemplate') || ''; 27 | var shadow = item.getFieldValue('custitem_kotn_shadow_template') || ''; 28 | if (tmplt != shadow) { 29 | item.setFieldValue('custitem_kotn_shadow_template', tmplt); 30 | nlapiSubmitRecord(item, {disabletriggers:true,ignoremandatoryfields:true, enablesourcing:false}); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | KotN-Netsuite 2 | ============= 3 | 4 | Various scripts I release to the Netsuite developer community. 5 | The *.ts are TypeScript files. I find Typescript quite helpful in dealing with the Netsuite API. 6 | Not great to use if you have a number of developers in your account. All the *.d.ts files are the type definitions used by typescript to import type signatures for external APIs. 7 | 8 | - AJAXFunctions.js is a sort of legacy thing I wrote back before Netsuite updated their JavaScript engine to include the new array functions. The useful thing about it now is KOTNUtil.sendJSResponse that is useful for dealing with SuiteScript responses as JSON and automatically dealing with some common jsonp callback patterns 9 | - simpleBatch.js handles governance management for long running Scheduled Scripts 10 | - batchProcess.js handles governance for re-scheduling a scheduled script. Most use cases now superseded by SimpleBatch.js 11 | - kotnMergeTemplate is meant as a library to provide a drop-in replacement for scripts using nlapiMergeRecord. This script detects whether the template Id refers to an old CRMSDK template or a Scriptable Template and provides a file similar to the one returned from nlapiMergeRecord. 12 | 13 | - exposeImageNames and exposeItemTemplate are the sources for a couple of bundles 156149 and 41518 respectively. These copy some values from item record fields to expose them for search criteria and results. 14 | 15 | - calc*Dates functions are examples of doing business day calculations. 16 | Originally written to calculate expected delivery dates. calcNSWBusinessDays includes Easter and mandated days that don't necessarily follow a standard date or something like 2nd Monday of the month pattern. -------------------------------------------------------------------------------- /exposeItemTemplate.js: -------------------------------------------------------------------------------- 1 | /// 2 | var kotnShadowItemTemplate; 3 | (function (kotnShadowItemTemplate) { 4 | /** 5 | * copy store template item to field available in searches 6 | * @param {string} type event type 7 | * @return {void} 8 | */ 9 | function itemBeforeSubmit(type) { 10 | if (type == 'edit' || type == 'create') { 11 | var tmplt = nlapiGetFieldText('storeitemtemplate'); 12 | var shadow = nlapiGetFieldValue('custitem_kotn_shadow_template'); 13 | if (tmplt != shadow) 14 | nlapiSetFieldValue('custitem_kotn_shadow_template', tmplt); 15 | } 16 | } 17 | kotnShadowItemTemplate.itemBeforeSubmit = itemBeforeSubmit; 18 | 19 | /** 20 | * expose the item template after bundle install. You'll need a deployment 21 | * for each type of item. e.g., Inventory Item, Non-Inventory Item, Serialized Item 22 | * @param {string} recType Record type supplied by the mass update runner 23 | * @param {string|number} recId Item internal id supplied by the mass update runner 24 | */ 25 | function massShadow(recType, recId) { 26 | var item = nlapiLoadRecord(recType, recId); 27 | var tmplt = item.getFieldText('storeitemtemplate') || ''; 28 | var shadow = item.getFieldValue('custitem_kotn_shadow_template') || ''; 29 | if (tmplt != shadow) { 30 | item.setFieldValue('custitem_kotn_shadow_template', tmplt); 31 | nlapiSubmitRecord(item, { disabletriggers: true, ignoremandatoryfields: true, enablesourcing: false }); 32 | } 33 | } 34 | kotnShadowItemTemplate.massShadow = massShadow; 35 | })(kotnShadowItemTemplate || (kotnShadowItemTemplate = {})); 36 | -------------------------------------------------------------------------------- /AJAXFunctions.js: -------------------------------------------------------------------------------- 1 | /// 2 | /* 3 | Utility Functions 4 | © 2008 - 2012 Brett Knights. 5 | This EULA grants you the following rights: 6 | Installation and Use. You may install and use an unlimited number of copies of the SOFTWARE PRODUCT. 7 | Reproduction and Distribution. You may reproduce and distribute an unlimited number of copies of the SOFTWARE PRODUCT 8 | either in whole or in part; each copy should include all copyright and trademark notices, and shall be accompanied by a copy of this EULA. 9 | Copies of the SOFTWARE PRODUCT may be distributed as a standalone product or included with your own product. 10 | Commercial Use. You may sell for profit and freely distribute scripts and/or compiled scripts that were created with the SOFTWARE PRODUCT. 11 | 12 | For permission, contact brett@knightsofthenet.com 13 | 14 | */ 15 | var KOTNUtil; 16 | (function (KOTNUtil) { 17 | function sendJSResponse(request, response, respObject) { 18 | var startTime = new Date().getTime(); 19 | response.setContentType('JAVASCRIPT'); 20 | var callbackFcn = request.getParameter("callback") || request.getParameter("jsoncallback"); 21 | if(callbackFcn) { 22 | response.writeLine(callbackFcn + "(" + JSON.stringify(respObject) + ");"); 23 | } else { 24 | response.writeLine(JSON.stringify(respObject)); 25 | } 26 | nlapiLogExecution("DEBUG", "sendJSResponse", (new Date().getTime() - startTime) + " ms"); 27 | } 28 | KOTNUtil.sendJSResponse = sendJSResponse; 29 | function unique(arr) { 30 | var u = []; 31 | noadd: 32 | for(var i = 0; i < arr.length; i++) { 33 | for(var k = 0; k < u.length; k++) { 34 | if(arr[i] == u[k]) { 35 | continue noadd; 36 | } 37 | } 38 | u.push(arr[i]); 39 | } 40 | return u; 41 | } 42 | KOTNUtil.unique = unique; 43 | function toJSON(target) { 44 | return JSON.stringify(target); 45 | } 46 | KOTNUtil.toJSON = toJSON; 47 | ; ; 48 | })(KOTNUtil || (KOTNUtil = {})); 49 | -------------------------------------------------------------------------------- /kotnMergeTemplate.js: -------------------------------------------------------------------------------- 1 | 2 | function kotnMergeTemplate(templateId, primType, primId, secType, secId, extraFields, outType){ 3 | 4 | var template = nlapiLoadRecord('emailtemplate', templateId); 5 | if('FREEMARKER' != template.getFieldValue('templateversion')){ 6 | return nlapiMergeRecord(templateId, primType, primId, secType, secId, extraFields); 7 | } 8 | 9 | var renderer = nlapiCreateTemplateRenderer(); 10 | 11 | var content = 'T' == template.getFieldValue('usesmedia') ? 12 | (function(){ 13 | var file = nlapiLoadFile(template.getFieldValue('mediaitem')); 14 | return file.getValue(); 15 | })() : 16 | template.getFieldValue('content'); 17 | 18 | var custFieldPatt = /\{\{([^\}]+)\}\}/g; 19 | content = content.replace(custFieldPatt, function(a,m){ 20 | return extraFields[m] || extraFields[m.toUpperCase()] || extraFields[m.toLowerCase()] || ''; 21 | }); 22 | 23 | var oldCustFieldPatt = /<(nl[^ >]+)>(\s*<\/\1>)?/ig; 24 | content = content.replace(oldCustFieldPatt, function(a,m){ 25 | return extraFields[m.toUpperCase()] || extraFields[m.toLowerCase()] || ''; 26 | }); 27 | 28 | 29 | var fillStandards = function (suppliedType, rec){ 30 | if(rec.getFieldValue('trandate') && suppliedType != 'transaction' ) renderer.addRecord('transaction', rec); 31 | if(rec.getFieldValue('entityid') && suppliedType != 'entity') renderer.addRecord('entity', rec); 32 | if('supportcase' == rec.getRecordType() && suppliedType != 'case') renderer.addRecord('case', rec); 33 | }; 34 | 35 | if(secType) { 36 | var secRec = nlapiLoadRecord(secType, secId); 37 | renderer.addRecord(secType, secRec); 38 | fillStandards(secType, secRec); 39 | } 40 | 41 | if(primType) { 42 | var primRec = nlapiLoadRecord(primType, primId); 43 | renderer.addRecord(primType, primRec); 44 | fillStandards(primType, primRec); 45 | } 46 | 47 | 48 | var getRendered = function (tmplt){ 49 | renderer.setTemplate(tmplt); 50 | return renderer.renderToString(); 51 | }; 52 | 53 | return nlapiCreateFile(getRendered(template.getFieldValue('subject')), outType || 'HTMLDOC', getRendered(content)); 54 | } 55 | -------------------------------------------------------------------------------- /simpleBatch.ts: -------------------------------------------------------------------------------- 1 | /// 2 | function simpleBatch(arr : any[], proc : (t :any, idx: number, a:any[]) => void, reserve? :number, maxMinutes? :number){ 3 | if(!arr || !arr.length) return; 4 | var maxUsage = reserve || 0; 5 | var breakTime = maxMinutes ? (new Date().getTime() + 60000*maxMinutes) : 0; 6 | var startUsage = nlapiGetContext().getRemainingUsage(); 7 | for(var i = 0; i< arr.length; i++){ 8 | if(startUsage < (maxUsage + 20) || (breakTime && new Date().getTime() > breakTime)){ 9 | var ys = nlapiYieldScript(); 10 | if(ys.status == 'FAILURE'){ 11 | nlapiLogExecution('ERROR', "Unable to Yield "+ ys.reason, ys.information); 12 | } 13 | nlapiLogExecution("AUDIT", "After resume had: "+ startUsage +" remaining vs max: "+ maxUsage); 14 | startUsage = nlapiGetContext().getRemainingUsage(); 15 | breakTime = maxMinutes ? (new Date().getTime() + 60000*maxMinutes) : 0; 16 | } 17 | proc(arr[i], i, arr); 18 | if(nlapiGetContext().getExecutionContext() == "scheduled") nlapiGetContext().setPercentComplete( ((100*i)/arr.length ).toFixed(1)); 19 | 20 | var endUsage = nlapiGetContext().getRemainingUsage(); 21 | var runUsage = startUsage - endUsage; 22 | if(maxUsage < runUsage) maxUsage = runUsage; 23 | startUsage = endUsage; 24 | } 25 | } 26 | 27 | function batchIterator(iter:()=>any, proc : (t :any, idx:number) => void, reserve? :number, maxMinutes? :number, beforeYield ?:() => void, afterYield ?:() => void){ 28 | var maxUsage = reserve || 0; 29 | var breakTime = maxMinutes ? (new Date().getTime() + 60000*maxMinutes) : 0; 30 | var startUsage = nlapiGetContext().getRemainingUsage(); 31 | var isScheduled = "scheduled" == nlapiGetContext().getExecutionContext(); 32 | var elemsProcessed = 0; 33 | var elem = iter(); 34 | while(elem && typeof elem != 'undefined'){ 35 | if(startUsage < (maxUsage + 20) || (breakTime && new Date().getTime() > breakTime)){ 36 | if(!isScheduled){ 37 | nlapiLogExecution("SYSTEM", "non-Scheduled run ending with "+startUsage +" units remaining"); 38 | break; 39 | } 40 | if(beforeYield) beforeYield(); 41 | var ys = nlapiYieldScript(); 42 | if(ys.status == 'FAILURE'){ 43 | nlapiLogExecution('ERROR', "Unable to Yield "+ ys.reason, ys.information); 44 | } 45 | nlapiLogExecution("AUDIT", "After resume had: "+ startUsage +" remaining vs max: "+ maxUsage); 46 | startUsage = nlapiGetContext().getRemainingUsage(); 47 | breakTime = maxMinutes ? (new Date().getTime() + 60000*maxMinutes) : 0; 48 | if(afterYield) afterYield(); 49 | } 50 | proc(elem, elemsProcessed); 51 | elemsProcessed++; 52 | var endUsage = nlapiGetContext().getRemainingUsage(); 53 | if(isScheduled) nlapiGetContext().setPercentComplete( (100*(startUsage - endUsage)/(startUsage)).toFixed(1)); 54 | var runUsage = startUsage - endUsage; 55 | if(maxUsage < runUsage) maxUsage = runUsage; 56 | startUsage = endUsage; 57 | elem = iter(); 58 | } 59 | } 60 | 61 | function dynamicBatch(arr : any[], proc : (t :any, idx:number) => void, reserve? :number, maxMinutes? :number, beforeYield ?:() => void, afterYield ?:() => void){ 62 | if(!arr || !arr.length) return; 63 | batchIterator( 64 | function(){ 65 | if(arr.length) return arr.shift(); 66 | return null; 67 | }, 68 | proc, 69 | reserve, maxMinutes, beforeYield, afterYield); 70 | } -------------------------------------------------------------------------------- /simpleBatch.js: -------------------------------------------------------------------------------- 1 | /// 2 | function simpleBatch(arr, proc, reserve, maxMinutes) { 3 | if (!arr || !arr.length) 4 | return; 5 | var maxUsage = reserve || 0; 6 | var breakTime = maxMinutes ? (new Date().getTime() + 60000 * maxMinutes) : 0; 7 | var startUsage = nlapiGetContext().getRemainingUsage(); 8 | for (var i = 0; i < arr.length; i++) { 9 | if (startUsage < (maxUsage + 20) || (breakTime && new Date().getTime() > breakTime)) { 10 | var ys = nlapiYieldScript(); 11 | if (ys.status == 'FAILURE') { 12 | nlapiLogExecution('ERROR', "Unable to Yield " + ys.reason, ys.information); 13 | } 14 | nlapiLogExecution("AUDIT", "After resume had: " + startUsage + " remaining vs max: " + maxUsage); 15 | startUsage = nlapiGetContext().getRemainingUsage(); 16 | breakTime = maxMinutes ? (new Date().getTime() + 60000 * maxMinutes) : 0; 17 | } 18 | proc(arr[i], i, arr); 19 | if (nlapiGetContext().getExecutionContext() == "scheduled") 20 | nlapiGetContext().setPercentComplete(((100 * i) / arr.length).toFixed(1)); 21 | 22 | var endUsage = nlapiGetContext().getRemainingUsage(); 23 | var runUsage = startUsage - endUsage; 24 | if (maxUsage < runUsage) 25 | maxUsage = runUsage; 26 | startUsage = endUsage; 27 | } 28 | } 29 | 30 | function batchIterator(iter, proc, reserve, maxMinutes, beforeYield, afterYield) { 31 | var maxUsage = reserve || 0; 32 | var breakTime = maxMinutes ? (new Date().getTime() + 60000 * maxMinutes) : 0; 33 | var startUsage = nlapiGetContext().getRemainingUsage(); 34 | var isScheduled = "scheduled" == nlapiGetContext().getExecutionContext(); 35 | var elemsProcessed = 0; 36 | var elem = iter(); 37 | while (elem && typeof elem != 'undefined') { 38 | if (startUsage < (maxUsage + 20) || (breakTime && new Date().getTime() > breakTime)) { 39 | if (!isScheduled) { 40 | nlapiLogExecution("SYSTEM", "non-Scheduled run ending with " + startUsage + " units remaining"); 41 | break; 42 | } 43 | if (beforeYield) 44 | beforeYield(); 45 | var ys = nlapiYieldScript(); 46 | if (ys.status == 'FAILURE') { 47 | nlapiLogExecution('ERROR', "Unable to Yield " + ys.reason, ys.information); 48 | } 49 | nlapiLogExecution("AUDIT", "After resume had: " + startUsage + " remaining vs max: " + maxUsage); 50 | startUsage = nlapiGetContext().getRemainingUsage(); 51 | breakTime = maxMinutes ? (new Date().getTime() + 60000 * maxMinutes) : 0; 52 | if (afterYield) 53 | afterYield(); 54 | } 55 | proc(elem, elemsProcessed); 56 | elemsProcessed++; 57 | var endUsage = nlapiGetContext().getRemainingUsage(); 58 | if (isScheduled) 59 | nlapiGetContext().setPercentComplete((100 * (startUsage - endUsage) / (startUsage)).toFixed(1)); 60 | var runUsage = startUsage - endUsage; 61 | if (maxUsage < runUsage) 62 | maxUsage = runUsage; 63 | startUsage = endUsage; 64 | elem = iter(); 65 | } 66 | } 67 | 68 | function dynamicBatch(arr, proc, reserve, maxMinutes, beforeYield, afterYield) { 69 | if (!arr || !arr.length) 70 | return; 71 | batchIterator(function () { 72 | if (arr.length) 73 | return arr.shift(); 74 | return null; 75 | }, proc, reserve, maxMinutes, beforeYield, afterYield); 76 | } 77 | -------------------------------------------------------------------------------- /batchProcess.ts: -------------------------------------------------------------------------------- 1 | /*jsl:option explicit*/ 2 | /* 3 | Utility Functions 4 | copyright 2008 - 2010 Brett Knights. All rights reserved. This material may not be reproduced, 5 | displayed, modified or distributed without the express prior written 6 | permission of the copyright holder. 7 | For permission, contact brett@knightsofthenet.com 8 | */ 9 | 10 | /// 11 | 12 | interface JobContext {getTargetsUsage: () =>number; getMaxUsage : () => number;} 13 | 14 | function batchProcess(getContext :(origContext : JobContext) => JobContext, getTargets: (ctx:JobContext, isRerunCheck: bool) => Object[], processTarget : (ctx : JobContext, simpleArg? : any) => bool, rerunParams : (ctx :JobContext) => void){ 15 | 16 | var targetUsage = 0; 17 | var rawContext : JobContext = { 18 | getTargetsUsage : function (){return targetUsage;}, 19 | getMaxUsage : function (){return targetUsage;} 20 | }; 21 | var context = getContext(rawContext); 22 | 23 | var targetStartUsage = nlapiGetContext().getRemainingUsage(); 24 | var targets = getTargets(context, false); 25 | targetUsage = targetStartUsage - nlapiGetContext().getRemainingUsage(); 26 | 27 | 28 | if(!targets || !targets.length){ 29 | nlapiLogExecution('DEBUG', 'batch process', 'No targets found to process'); 30 | return; 31 | } 32 | targets = [].concat(targets); // make it a true array and make it independent of orig target; sometimes NS weirdness 33 | try{ 34 | 35 | var targetCount = 0; 36 | var maxUsage = 0; 37 | var origTargetLength = targets.length; 38 | each(targets, function(idx, target){ 39 | var initUsage = nlapiGetContext().getRemainingUsage(); 40 | try{ 41 | 42 | var flag = processTarget.call(typeof target == 'object' ? target : {}, context, target); 43 | if(typeof flag != 'undefined' && !flag) return false; 44 | 45 | }catch(e){ 46 | nlapiLogExecution('ERROR', 'error processing target', (e.message || e.toString()) + (e.getStackTrace ? '\n\n'+ e.getStackTrace().join('\n') : '')); 47 | return false; // exit on failure. processTarget should catch own errors to continue on failure. 48 | } 49 | var remainUsage = nlapiGetContext().getRemainingUsage(); 50 | var passUsage = initUsage - remainUsage; 51 | if(passUsage > maxUsage) maxUsage = passUsage; 52 | 53 | targetCount++; 54 | if(nlapiGetContext().getExecutionContext() == "scheduled"){ 55 | var usageToFinish = targets.length * maxUsage; 56 | if(targets.length && usageToFinish < remainUsage){ //in simple case targets.length decrements once per iteration 57 | var pctRemaining = targets.length / (targets.length + targetCount); 58 | nlapiGetContext().setPercentComplete( (100*( 1 - pctRemaining)).toFixed(1)); 59 | }else nlapiGetContext().setPercentComplete( (100*( 1 -(remainUsage/targetStartUsage))).toFixed(1)); 60 | } 61 | 62 | var canGo = remainUsage > (maxUsage + targetUsage + 10); // an iteration plus the follow up targetUsage + 10 63 | context.getMaxUsage = function(){return maxUsage;}; 64 | nlapiLogExecution("DEBUG", "usage profile", "remaining: " + remainUsage +"\npassUsage: "+ passUsage +"\nmaxUsage: "+maxUsage); 65 | 66 | if(!canGo) nlapiLogExecution('AUDIT', 'Processing Targets', 'processed: ' + targetCount +' targets'); 67 | 68 | return canGo; 69 | }); 70 | 71 | var remainder = getTargets(context, true); 72 | 73 | if(remainder && remainder.length){ 74 | if(nlapiGetContext().getExecutionContext() == "scheduled") { //check executionContext to avoid invalid calls in debugger 75 | var status = nlapiScheduleScript(nlapiGetContext().getScriptId(), nlapiGetContext().getDeploymentId(), rerunParams(context)); 76 | nlapiLogExecution('AUDIT', 'Processing Targets', "finished run " + remainder.length + " targets left to process. Rescheduled: " + status); 77 | }else nlapiLogExecution('AUDIT', 'Processing Targets', "finished non-scheduled run " + remainder.length + " targets left to process."); 78 | } 79 | }catch(e){ 80 | nlapiLogExecution('ERROR', e.message || e.toString(), e.message || e.toString() + (e.getStackTrace ? '\n\n' + e.getStackTrace().join('\n') : '')); 81 | } 82 | 83 | 84 | function each(arr, fcn){ 85 | var idx = 0; 86 | while(true){ 87 | if (!arr || !arr.length) return; 88 | var target = arr.shift(); // use shift so that processTarget can add or remove elements from the list 89 | if(!target) return; 90 | var x = fcn.call(typeof target == 'object' ? target : null, idx, target); 91 | if(typeof x != 'undefined' && x !== null && !(x)) return; 92 | idx++; 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /batchProcess.js: -------------------------------------------------------------------------------- 1 | function batchProcess(getContext, getTargets, processTarget, rerunParams) { 2 | var targetUsage = 0; 3 | var rawContext = { 4 | getTargetsUsage: function () { 5 | return targetUsage; 6 | }, 7 | getMaxUsage: function () { 8 | return targetUsage; 9 | } 10 | }; 11 | var context = getContext(rawContext); 12 | var targetStartUsage = nlapiGetContext().getRemainingUsage(); 13 | var targets = getTargets(context, false); 14 | targetUsage = targetStartUsage - nlapiGetContext().getRemainingUsage(); 15 | if(!targets || !targets.length) { 16 | nlapiLogExecution('DEBUG', 'batch process', 'No targets found to process'); 17 | return; 18 | } 19 | targets = [].concat(targets)// make it a true array and make it independent of orig target; sometimes NS weirdness 20 | ; 21 | try { 22 | var targetCount = 0; 23 | var maxUsage = 0; 24 | var origTargetLength = targets.length; 25 | each(targets, function (idx, target) { 26 | var initUsage = nlapiGetContext().getRemainingUsage(); 27 | try { 28 | var flag = processTarget.call(typeof target == 'object' ? target : { 29 | }, context, target); 30 | if(typeof flag != 'undefined' && !flag) { 31 | return false; 32 | } 33 | } catch (e) { 34 | nlapiLogExecution('ERROR', 'error processing target', (e.message || e.toString()) + (e.getStackTrace ? '\n\n' + e.getStackTrace().join('\n') : '')); 35 | return false;// exit on failure. processTarget should catch own errors to continue on failure. 36 | 37 | } 38 | var remainUsage = nlapiGetContext().getRemainingUsage(); 39 | var passUsage = initUsage - remainUsage; 40 | if(passUsage > maxUsage) { 41 | maxUsage = passUsage; 42 | } 43 | targetCount++; 44 | if(nlapiGetContext().getExecutionContext() == "scheduled") { 45 | var usageToFinish = targets.length * maxUsage; 46 | if(targets.length && usageToFinish < remainUsage) { 47 | //in simple case targets.length decrements once per iteration 48 | var pctRemaining = targets.length / (targets.length + targetCount); 49 | nlapiGetContext().setPercentComplete((100 * (1 - pctRemaining)).toFixed(1)); 50 | } else { 51 | nlapiGetContext().setPercentComplete((100 * (1 - (remainUsage / targetStartUsage))).toFixed(1)); 52 | } 53 | } 54 | var canGo = remainUsage > (maxUsage + targetUsage + 10);// an iteration plus the follow up targetUsage + 10 55 | 56 | context.getMaxUsage = function () { 57 | return maxUsage; 58 | }; 59 | nlapiLogExecution("DEBUG", "usage profile", "remaining: " + remainUsage + "\npassUsage: " + passUsage + "\nmaxUsage: " + maxUsage); 60 | if(!canGo) { 61 | nlapiLogExecution('AUDIT', 'Processing Targets', 'processed: ' + targetCount + ' targets'); 62 | } 63 | return canGo; 64 | }); 65 | var remainder = getTargets(context, true); 66 | if(remainder && remainder.length) { 67 | if(nlapiGetContext().getExecutionContext() == "scheduled") { 68 | //check executionContext to avoid invalid calls in debugger 69 | var status = nlapiScheduleScript(nlapiGetContext().getScriptId(), nlapiGetContext().getDeploymentId(), rerunParams(context)); 70 | nlapiLogExecution('AUDIT', 'Processing Targets', "finished run " + remainder.length + " targets left to process. Rescheduled: " + status); 71 | } else { 72 | nlapiLogExecution('AUDIT', 'Processing Targets', "finished non-scheduled run " + remainder.length + " targets left to process."); 73 | } 74 | } 75 | } catch (e) { 76 | nlapiLogExecution('ERROR', e.message || e.toString(), e.message || e.toString() + (e.getStackTrace ? '\n\n' + e.getStackTrace().join('\n') : '')); 77 | } 78 | function each(arr, fcn) { 79 | var idx = 0; 80 | while(true) { 81 | if(!arr || !arr.length) { 82 | return; 83 | } 84 | var target = arr.shift();// use shift so that processTarget can add or remove elements from the list 85 | 86 | if(!target) { 87 | return; 88 | } 89 | var x = fcn.call(typeof target == 'object' ? target : null, idx, target); 90 | if(typeof x != 'undefined' && x !== null && !(x)) { 91 | return; 92 | } 93 | idx++; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /calculateShippingDates.js: -------------------------------------------------------------------------------- 1 | /*jsl:option explicit*/ 2 | 3 | function ShippingDays(){ 4 | var ONE_DAY = 24 * 3600000; 5 | function addDay(d){ return new Date(d.getTime() + ONE_DAY);} 6 | 7 | var holidays = (function(){ 8 | 9 | /* 10 | based on UPS holidays to calculate shipping days. 11 | 12 | Memorial Day - May 30, 2011* (4th Monday in May 13 | Independence Day - July 4, 2011* 14 | Labor Day - September 5, 2011* 1st Monday in Sept. 15 | Thanksgiving Day - November 24, 2011* Last Thursday in Oct 16 | Day after Thanksgiving - November 25, 2011** 17 | Christmas (observed) - December 26, 2011* 18 | New Year's Eve - December 31, 2011 19 | New Year's Day (observed) - January 2, 2012* 20 | */ 21 | 22 | 23 | var now = new Date(); 24 | var baseYear = now.getFullYear(); 25 | 26 | 27 | function getNth(month, targetday, nTh){ 28 | var useYear = month === 0 ? baseYear + 1 : baseYear; 29 | var monthStart = new Date(useYear , month, 1); 30 | var monthFrom = monthStart.getDay(); 31 | var offset = 7 * (nTh - 1) + (function(){ 32 | if( targetday == monthFrom ) return 0; 33 | if( targetday < monthFrom) return (7-(monthFrom - targetday)); 34 | return (targetday - monthFrom); 35 | })(); 36 | return new Date(monthStart.getFullYear(), monthStart.getMonth(), 1 + offset); 37 | } 38 | 39 | 40 | function getHoliday(month, day){ 41 | var useYear = month === 0 ? baseYear + 1 : baseYear; 42 | return new Date(useYear, month, day); 43 | } 44 | 45 | function getFollowing(month,day){ 46 | var useYear = month === 0 ? baseYear + 1 : baseYear; 47 | var d = new Date(useYear, month, day); 48 | var isDay = d.getDay(); 49 | if(!(isDay === 0 || isDay === 6)) return null; 50 | 51 | while(isDay === 0 || isDay === 6) { 52 | d = addDay(d); 53 | isDay = d.getDay(); 54 | } 55 | return d; 56 | } 57 | 58 | function getLast(month, targetday){ 59 | var fourth = getNth(month, targetday, 4); 60 | var fifth = new Date(fourth.getTime() + 7 * ONE_DAY); 61 | return fourth.getMonth() == fifth.getMonth() ? fifth : fourth; 62 | } 63 | 64 | 65 | function includeDay(d){if(d) holidays.push(d);} 66 | 67 | var holidays = []; 68 | 69 | //months in Javascript count from 0. e.g. May is month 4 70 | includeDay(getNth(4,1,4)); // Memorial Day 4th Monday in May 71 | includeDay(getHoliday(6,4)); // July 4th 72 | includeDay(getFollowing(6,4)); // following Monday if on weekend 73 | includeDay(getNth(8,1,1)); //Labour Day 1st Monday in September 74 | includeDay(getLast(10,4)); // Thanksgiving last Thursday in Nov. 75 | includeDay(addDay(getLast(10,4))); // day after thanksgiving 76 | includeDay(getHoliday(11,25)); //Christmas 77 | includeDay(getFollowing(11,25)); //Christmas observed 78 | includeDay(getHoliday(11,31)); //New Years Eve 79 | includeDay(getHoliday(0,1)); //New Years 80 | includeDay(getFollowing(0,1)); //New Years observed 81 | 82 | baseYear++; // just calc next year too. Allow 365 day lookup from wherever in the year 83 | 84 | includeDay(getNth(4,1,4)); // Memorial Day 4th Monday in May 85 | includeDay(getHoliday(6,4)); // July 4th 86 | includeDay(getFollowing(6,4)); // following Monday if on weekend 87 | includeDay(getNth(8,1,1)); //Labour Day 1st Monday in September 88 | includeDay(getLast(10,4)); // Thanksgiving last Thursday in Nov. 89 | includeDay(addDay(getLast(10,4))); // day after thanksgiving 90 | includeDay(getHoliday(11,25)); //Christmas 91 | includeDay(getFollowing(11,25)); //Christmas observed 92 | includeDay(getHoliday(11,31)); //New Years Eve 93 | includeDay(getHoliday(0,1)); //New Years 94 | includeDay(getFollowing(0,1)); //New Years observed 95 | 96 | 97 | return holidays; 98 | })(); 99 | 100 | function isBusinessDay(date){ 101 | var weekDay = date.getDay(); 102 | if(weekDay === 0 || weekDay === 6) return false; 103 | for(var i = 0; i< holidays.length; i++){ 104 | if(holidays[i].getFullYear() == date.getFullYear() && 105 | holidays[i].getMonth() == date.getMonth() && 106 | holidays[i].getDate() == date.getDate()) return false; 107 | } 108 | return true; 109 | } 110 | 111 | this.addDays = function(date, n){ 112 | if(n > 255) throw new Error("function only works on dates within about a calendar year"); 113 | var bd = date; 114 | var daysAdded = 0; 115 | while(daysAdded < n){ 116 | bd = addDay(bd); daysAdded++; 117 | while(!isBusinessDay(bd)) bd = addDay(bd); 118 | } 119 | return bd; 120 | }; 121 | 122 | this.getLastOfMonth = function(date){ 123 | var thisMonth = date.getMonth(); 124 | var lastDay = new Date(date.getTime()); 125 | while(isBusinessDay(lastDay) && lastDay.getMonth() == thisMonth){ 126 | lastDay = addDay(lastDay); 127 | } 128 | if(lastDay.getMonth() == thisMonth) return lastDay; // found one; otherwise back up 129 | do{ 130 | lastDay = new Date(lastDay.getDate() - ONE_DAY); 131 | }while(!isBusinessDay(lastDay)); 132 | return lastDay; 133 | }; 134 | } 135 | 136 | 137 | function getWFShippingDays(){ 138 | var fromDate = nlapiGetContext().getSetting('SCRIPT', 'custscript_wf_ship_from_date'); 139 | var days = parseInt(nlapiGetContext().getSetting('SCRIPT', 'custscript_wf_shipdays'),10); 140 | 141 | nlapiLogExecution("DEBUG","get "+ days + " shippping days from : "+ (fromDate || new Date())); 142 | 143 | return nlapiDateToString(new ShippingDays().addDays(fromDate ? nlapiStringToDate(fromDate) : new Date(), days)); 144 | } -------------------------------------------------------------------------------- /exposeImageNames.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module kotnShadowImageNames{ 4 | 5 | /** 6 | * copy standard store images allow image names in feeds 7 | * @param {string} type event type 8 | * @return {void} 9 | */ 10 | export function itemBeforeSubmit(type) { 11 | if (type == 'edit' || type == 'create') { 12 | var imageName = nlapiGetFieldText('storedisplayimage'); 13 | if (imageName && imageName != nlapiGetFieldValue('custitem_kotn_image_name')) nlapiSetFieldValue('custitem_kotn_image_name', imageName); 14 | 15 | var thumbnailName = nlapiGetFieldText('storedisplaythumbnail'); 16 | if (thumbnailName && thumbnailName != nlapiGetFieldValue('custitem_kotn_thumbnail_name')) nlapiSetFieldValue('custitem_kotn_thumbnail_name', thumbnailName); 17 | } 18 | } 19 | 20 | export function itemAfterSubmit(type){ 21 | nlapiLogExecution('DEBUG', type +' after submit with matrix type: '+ nlapiGetFieldValue('matrixtype')); 22 | if(type == 'edit' || type == 'create' || type == 'xedit'){ 23 | if(!nlapiGetContext().getFeature('MATRIXITEMS') ) return; 24 | try{ 25 | var oldRec = nlapiGetOldRecord(); 26 | var imageName = nlapiGetFieldValue('custitem_kotn_image_name'); 27 | if(imageName && oldRec && oldRec.getFieldValue('custitem_kotn_image_name') == imageName) imageName = null; 28 | 29 | var thumbnailName = nlapiGetFieldValue('custitem_kotn_thumbnail_name'); 30 | if(thumbnailName && oldRec && oldRec.getFieldValue('custitem_kotn_thumbnail_name') == thumbnailName) thumbnailName = null; 31 | 32 | if(nlapiGetRecordId() && (imageName || thumbnailName)){ 33 | var childItems = nlapiSearchRecord('item', null, [ 34 | new nlobjSearchFilter('parent', null, 'anyof', [nlapiGetRecordId()]), 35 | new nlobjSearchFilter('matrixchild', null, 'is', 'T'), 36 | new nlobjSearchFilter('isinactive', null, 'is', 'F') 37 | ],[ 38 | new nlobjSearchColumn('custitem_kotn_image_name'), 39 | new nlobjSearchColumn('custitem_kotn_thumbnail_name') 40 | ]); 41 | if(childItems) { 42 | var updateFields : string[] = [], updateValues : string[] = []; 43 | if(imageName){ 44 | updateFields.push('custitem_kotn_image_name'); 45 | updateValues.push(imageName); 46 | } 47 | if(thumbnailName){ 48 | updateFields.push('custitem_kotn_thumbnail_name'); 49 | updateValues.push(thumbnailName); 50 | } 51 | nlapiLogExecution("DEBUG", "Updating " + childItems.length +" for image names"); 52 | 53 | childItems.forEach(function(c){ 54 | if(c.getValue('custitem_kotn_image_name') == imageName && c.getValue('custitem_kotn_thumbnail_name') == thumbnailName) return; 55 | nlapiSubmitField(c.getRecordType(), c.getId(),updateFields, updateValues,{disabletriggers:true, enablesourcing:false}); 56 | }); 57 | 58 | } 59 | } 60 | }catch(e){ 61 | nlapiLogExecution('ERROR', 'updating child items', (e.message || e.toString()) + (e.getStackTrace ? (' \n \n' + e.getStackTrace().join(' \n')) : '')); 62 | } 63 | } 64 | } 65 | 66 | /** 67 | * prefill these fields after install. You'll need a deployment 68 | * for each type of item. e.g., Inventory Item, Non-Inventory Item, Serialized Item 69 | * @param {string} recType Record type supplied by the mass update runner 70 | * @param {string|number} recId Item internal id supplied by the mass update runner 71 | */ 72 | export function massImages(recType, recId) { 73 | var item = nlapiLoadRecord(recType, recId); 74 | var needSave = false; 75 | 76 | var imageName = item.getFieldText('storedisplayimage') || ''; 77 | if (imageName && imageName != item.getFieldValue('custitem_kotn_image_name')){ 78 | item.setFieldValue('custitem_kotn_image_name', imageName); 79 | needSave = true; 80 | } 81 | 82 | var thumbnailName = item.getFieldText('storedisplaythumbnail'); 83 | if (thumbnailName && thumbnailName != item.getFieldValue('custitem_kotn_thumbnail_name')){ 84 | item.setFieldValue('custitem_kotn_thumbnail_name', thumbnailName); 85 | needSave = true; 86 | } 87 | 88 | if (needSave) { 89 | nlapiSubmitRecord(item, {disabletriggers:true,ignoremandatoryfields:true, enablesourcing:false}); 90 | } 91 | 92 | if(!nlapiGetContext().getFeature('MATRIXITEMS') ) return; 93 | 94 | var filters = [ 95 | new nlobjSearchFilter('parent', null, 'anyof', [recId]), 96 | new nlobjSearchFilter('matrixchild', null, 'is', 'T'), 97 | new nlobjSearchFilter('isinactive', null, 'is', 'F') 98 | ]; 99 | 100 | // var imageClause = imageName ? "when '"+ imageName +"' != {custitem_kotn_image_name} then 1 " : ''; 101 | // var thumbClause = thumbnailName ? "when '"+ thumbnailName +"' != {custitem_kotn_thumbnail_name} then 1 " : ''; 102 | // if(imageClause || thumbClause){ 103 | // filters.push(new nlobjSearchFilter('formulanumeric', null, 'equalto', '1'). 104 | // setFormula("case "+ imageClause +" "+ thumbClause +" else 0 end")); 105 | // 106 | // nlapiLogExecution('DEBUG', 'using formula to find children to update', filters.slice(-1)[0].getFormula()); 107 | // } 108 | 109 | var childItems = nlapiSearchRecord('item', null, filters, [new nlobjSearchColumn('custitem_kotn_image_name'), new nlobjSearchColumn('custitem_kotn_thumbnail_name')]); 110 | if(childItems) { 111 | var updateFields : string[] = [], updateValues : string[] = []; 112 | if(imageName){ 113 | updateFields.push('custitem_kotn_image_name'); 114 | updateValues.push(imageName); 115 | } 116 | if(thumbnailName){ 117 | updateFields.push('custitem_kotn_thumbnail_name'); 118 | updateValues.push(thumbnailName); 119 | } 120 | nlapiLogExecution('DEBUG', 'applying image update to '+ childItems.length, JSON.stringify(updateFields) +'\n\twith\n'+ JSON.stringify(updateValues)); 121 | try{ 122 | childItems.forEach(function(c){ 123 | if(c.getValue('custitem_kotn_image_name') == imageName && c.getValue('custitem_kotn_thumbnail_name') == thumbnailName) return; 124 | nlapiSubmitField(c.getRecordType(), c.getId(),updateFields, updateValues,{disabletriggers:true, enablesourcing:false}); 125 | }); 126 | }catch(e){ 127 | // probably governance. 128 | nlapiLogExecution('ERROR', 'updating child items', (e.message || e.toString()) + (e.getStackTrace ? (' \n \n' + e.getStackTrace().join(' \n')) : '')); 129 | } 130 | } 131 | 132 | } 133 | } -------------------------------------------------------------------------------- /exposeImageNames.js: -------------------------------------------------------------------------------- 1 | /// 2 | var kotnShadowImageNames; 3 | (function (kotnShadowImageNames) { 4 | /** 5 | * copy standard store images allow image names in feeds 6 | * @param {string} type event type 7 | * @return {void} 8 | */ 9 | function itemBeforeSubmit(type) { 10 | if (type == 'edit' || type == 'create') { 11 | var imageName = nlapiGetFieldText('storedisplayimage'); 12 | if (imageName && imageName != nlapiGetFieldValue('custitem_kotn_image_name')) 13 | nlapiSetFieldValue('custitem_kotn_image_name', imageName); 14 | var thumbnailName = nlapiGetFieldText('storedisplaythumbnail'); 15 | if (thumbnailName && thumbnailName != nlapiGetFieldValue('custitem_kotn_thumbnail_name')) 16 | nlapiSetFieldValue('custitem_kotn_thumbnail_name', thumbnailName); 17 | } 18 | } 19 | kotnShadowImageNames.itemBeforeSubmit = itemBeforeSubmit; 20 | function itemAfterSubmit(type) { 21 | nlapiLogExecution('DEBUG', type + ' after submit with matrix type: ' + nlapiGetFieldValue('matrixtype')); 22 | if (type == 'edit' || type == 'create' || type == 'xedit') { 23 | if (!nlapiGetContext().getFeature('MATRIXITEMS')) 24 | return; 25 | try { 26 | var oldRec = nlapiGetOldRecord(); 27 | var imageName = nlapiGetFieldValue('custitem_kotn_image_name'); 28 | if (imageName && oldRec && oldRec.getFieldValue('custitem_kotn_image_name') == imageName) 29 | imageName = null; 30 | var thumbnailName = nlapiGetFieldValue('custitem_kotn_thumbnail_name'); 31 | if (thumbnailName && oldRec && oldRec.getFieldValue('custitem_kotn_thumbnail_name') == thumbnailName) 32 | thumbnailName = null; 33 | if (nlapiGetRecordId() && (imageName || thumbnailName)) { 34 | var childItems = nlapiSearchRecord('item', null, [ 35 | new nlobjSearchFilter('parent', null, 'anyof', [nlapiGetRecordId()]), 36 | new nlobjSearchFilter('matrixchild', null, 'is', 'T'), 37 | new nlobjSearchFilter('isinactive', null, 'is', 'F') 38 | ], [ 39 | new nlobjSearchColumn('custitem_kotn_image_name'), 40 | new nlobjSearchColumn('custitem_kotn_thumbnail_name') 41 | ]); 42 | if (childItems) { 43 | var updateFields = [], updateValues = []; 44 | if (imageName) { 45 | updateFields.push('custitem_kotn_image_name'); 46 | updateValues.push(imageName); 47 | } 48 | if (thumbnailName) { 49 | updateFields.push('custitem_kotn_thumbnail_name'); 50 | updateValues.push(thumbnailName); 51 | } 52 | nlapiLogExecution("DEBUG", "Updating " + childItems.length + " for image names"); 53 | childItems.forEach(function (c) { 54 | if (c.getValue('custitem_kotn_image_name') == imageName && c.getValue('custitem_kotn_thumbnail_name') == thumbnailName) 55 | return; 56 | nlapiSubmitField(c.getRecordType(), c.getId(), updateFields, updateValues, { disabletriggers: true, enablesourcing: false }); 57 | }); 58 | } 59 | } 60 | } 61 | catch (e) { 62 | nlapiLogExecution('ERROR', 'updating child items', (e.message || e.toString()) + (e.getStackTrace ? (' \n \n' + e.getStackTrace().join(' \n')) : '')); 63 | } 64 | } 65 | } 66 | kotnShadowImageNames.itemAfterSubmit = itemAfterSubmit; 67 | /** 68 | * prefill these fields after install. You'll need a deployment 69 | * for each type of item. e.g., Inventory Item, Non-Inventory Item, Serialized Item 70 | * @param {string} recType Record type supplied by the mass update runner 71 | * @param {string|number} recId Item internal id supplied by the mass update runner 72 | */ 73 | function massImages(recType, recId) { 74 | var item = nlapiLoadRecord(recType, recId); 75 | var needSave = false; 76 | var imageName = item.getFieldText('storedisplayimage') || ''; 77 | if (imageName && imageName != item.getFieldValue('custitem_kotn_image_name')) { 78 | item.setFieldValue('custitem_kotn_image_name', imageName); 79 | needSave = true; 80 | } 81 | var thumbnailName = item.getFieldText('storedisplaythumbnail'); 82 | if (thumbnailName && thumbnailName != item.getFieldValue('custitem_kotn_thumbnail_name')) { 83 | item.setFieldValue('custitem_kotn_thumbnail_name', thumbnailName); 84 | needSave = true; 85 | } 86 | if (needSave) { 87 | nlapiSubmitRecord(item, { disabletriggers: true, ignoremandatoryfields: true, enablesourcing: false }); 88 | } 89 | if (!nlapiGetContext().getFeature('MATRIXITEMS')) 90 | return; 91 | var filters = [ 92 | new nlobjSearchFilter('parent', null, 'anyof', [recId]), 93 | new nlobjSearchFilter('matrixchild', null, 'is', 'T'), 94 | new nlobjSearchFilter('isinactive', null, 'is', 'F') 95 | ]; 96 | // var imageClause = imageName ? "when '"+ imageName +"' != {custitem_kotn_image_name} then 1 " : ''; 97 | // var thumbClause = thumbnailName ? "when '"+ thumbnailName +"' != {custitem_kotn_thumbnail_name} then 1 " : ''; 98 | // if(imageClause || thumbClause){ 99 | // filters.push(new nlobjSearchFilter('formulanumeric', null, 'equalto', '1'). 100 | // setFormula("case "+ imageClause +" "+ thumbClause +" else 0 end")); 101 | // 102 | // nlapiLogExecution('DEBUG', 'using formula to find children to update', filters.slice(-1)[0].getFormula()); 103 | // } 104 | var childItems = nlapiSearchRecord('item', null, filters, [new nlobjSearchColumn('custitem_kotn_image_name'), new nlobjSearchColumn('custitem_kotn_thumbnail_name')]); 105 | if (childItems) { 106 | var updateFields = [], updateValues = []; 107 | if (imageName) { 108 | updateFields.push('custitem_kotn_image_name'); 109 | updateValues.push(imageName); 110 | } 111 | if (thumbnailName) { 112 | updateFields.push('custitem_kotn_thumbnail_name'); 113 | updateValues.push(thumbnailName); 114 | } 115 | nlapiLogExecution('DEBUG', 'applying image update to ' + childItems.length, JSON.stringify(updateFields) + '\n\twith\n' + JSON.stringify(updateValues)); 116 | try { 117 | childItems.forEach(function (c) { 118 | if (c.getValue('custitem_kotn_image_name') == imageName && c.getValue('custitem_kotn_thumbnail_name') == thumbnailName) 119 | return; 120 | nlapiSubmitField(c.getRecordType(), c.getId(), updateFields, updateValues, { disabletriggers: true, enablesourcing: false }); 121 | }); 122 | } 123 | catch (e) { 124 | // probably governance. 125 | nlapiLogExecution('ERROR', 'updating child items', (e.message || e.toString()) + (e.getStackTrace ? (' \n \n' + e.getStackTrace().join(' \n')) : '')); 126 | } 127 | } 128 | } 129 | kotnShadowImageNames.massImages = massImages; 130 | })(kotnShadowImageNames || (kotnShadowImageNames = {})); 131 | -------------------------------------------------------------------------------- /SuiteScriptAPITS.d.ts: -------------------------------------------------------------------------------- 1 | declare function nlapiCopyRecord(type:string, id:string, initializeValues?:Object): nlobjRecord; 2 | declare function nlapiLoadRecord(type: string, id: string, initializeValues? : any): nlobjRecord; 3 | declare function nlapiCreateRecord(type: string, initializeValues?: any): nlobjRecord; 4 | declare function nlapiSubmitRecord(record :nlobjRecord, doSourcing? : boolean, ignoreMandatoryFields? : boolean): string; 5 | declare function nlapiSubmitRecord(record :nlobjRecord, overrides? : serverSubmitRecordFlags): string; 6 | declare function nlapiSubmitRecord(record :nlobjRecord, overrides : clientSubmitRecordFlags): string; 7 | 8 | declare function nlapiDeleteRecord(type : string, id : string): void; 9 | declare function nlapiSearchRecord(type : string, searchid? : number, srchFilter? : nlobjSearchFilter, column? : nlobjSearchColumn): nlobjSearchResult[]; 10 | declare function nlapiSearchRecord(type : string, searchid? : number, srchFilter? : nlobjSearchFilter, columns? : nlobjSearchColumn[]): nlobjSearchResult[]; 11 | declare function nlapiSearchRecord(type : string, searchid? : number, srchFilters? : Object[], column? : nlobjSearchColumn): nlobjSearchResult[]; 12 | declare function nlapiSearchRecord(type : string, searchid? : number, srchFilters? : Object[], columns? : nlobjSearchColumn[]): nlobjSearchResult[]; 13 | declare function nlapiSearchRecord(type : string, searchid? : string, srchFilter? : nlobjSearchFilter, column? : nlobjSearchColumn): nlobjSearchResult[]; 14 | declare function nlapiSearchRecord(type : string, searchid? : string, srchFilter? : nlobjSearchFilter, columns? : nlobjSearchColumn[]): nlobjSearchResult[]; 15 | declare function nlapiSearchRecord(type : string, searchid? : string, srchFilters? : Object[], column? : nlobjSearchColumn): nlobjSearchResult[]; 16 | declare function nlapiSearchRecord(type : string, searchid? : string, srchFilters? : Object[], columns? : nlobjSearchColumn[]): nlobjSearchResult[]; 17 | declare function nlapiCreateSearch(type : string, srchFilters? : Object[], columns? : nlobjSearchColumn[]): nlobjSearch; 18 | declare function nlapiLoadSearch(type:string, id:string):nlobjSearch; 19 | declare function nlapiSearchGlobal(keywords :string): any[]; 20 | declare function nlapiSearchDuplicate(type :string, fields :string[], id :string): any[]; 21 | declare function nlapiTransformRecord(type :string, id : string, transformType : string, transformValues? : Object): nlobjRecord; 22 | declare function nlapiTransformRecord(type :string, id : number, transformType : string, transformValues? : Object): nlobjRecord; 23 | declare function nlapiLookupField(type :string , id :string, fields :string[], text?: boolean): any; 24 | declare function nlapiLookupField(type :string , id :string, field :string, text?: boolean): string; 25 | 26 | declare function nlapiSubmitField(type : string, id : string, fields : string[], values : string[], doSourcing? : boolean): void; 27 | declare function nlapiSubmitField(type : string, id : string, field : string, value : string, doSourcing? : boolean): void; 28 | declare function nlapiSubmitField(type : string, id : string, fields : string[], values : string[], props:serverSubmitFieldFlags): void; 29 | declare function nlapiSubmitField(type : string, id : string, field : string, value : string, props:serverSubmitFieldFlags): void; 30 | declare function nlapiSubmitField(type : string, id : string, field : string, value : number, props:serverSubmitFieldFlags): void; 31 | declare function nlapiSubmitField(type : string, id : string, fields : string[], values : string[], props:clientSubmitFieldFlags): void; 32 | declare function nlapiSubmitField(type : string, id : string, field : string, value : string, props:clientSubmitFieldFlags): void; 33 | 34 | declare function nlapiAttachRecord(type1 : string, id1 :string, type2 :string, id2 :string, properties? : Object): void; 35 | declare function nlapiDetachRecord(type1 :string, id1 :string, type2 :string, id2 :string, properties?: Object): void; 36 | declare function nlapiResolveURL(type :string, subtype : string, id? : string, pagemode? : boolean): string; 37 | declare function nlapiSetRedirectURL(type : string, subtype : string, id? : string, pagemode? : boolean, parameters? : Object): void; 38 | declare function nlapiRequestURL(url : string, postdata? : any , headers? : any, callbackOrMethod? : any, httpMethod? : string): nlobjResponse; 39 | declare function nlapiGetContext() : nlobjContext; 40 | declare function nlapiGetUser() : string; 41 | declare function nlapiGetRole() : string; 42 | declare function nlapiGetDepartment(): void; 43 | declare function nlapiGetLocation(): void; 44 | declare function nlapiGetSubsidiary(): void; 45 | declare function nlapiGetRecordType(): string; 46 | declare function nlapiGetRecordId(): string; 47 | declare function nlapiSendEmail(from : string, to : string, subject : string, body : string, cc? : any, bcc? : any, records? : any, files? : any, notifySenderOnBounce?:boolean, internalOnly?:boolean, replyTo?:string): void; 48 | declare function nlapiSendCampaignEmail(campaigneventid :string, recipientid :string): void; 49 | declare function nlapiSendFax(from :string, to :string, subject :string, body :string, records :string, files :string[]): void; 50 | declare function nlapiGetField(fldnam :string): nlobjField; 51 | declare function nlapiGetMatrixField(type :string, fldnam :string, column :string): void; 52 | declare function nlapiGetLineItemField(type : string, fldnam : string, linenum : number): nlobjField; 53 | declare function nlapiGetLineItemMatrixField(type : string, fldnam : string, linenum : number, column : number) : string; 54 | declare function nlapiGetFieldValue(fldnam : string) : string; 55 | declare function nlapiSetFieldValue(fldnam : string, value : string, firefieldchanged? : boolean, synchronous? : boolean): void; 56 | declare function nlapiSetFieldValue(fldnam : string, value : number, firefieldchanged? : boolean, synchronous? : boolean): void; 57 | declare function nlapiGetFieldText(fldnam : string): string; 58 | declare function nlapiSetFieldText(fldnam : string, txt : string, firefieldchanged? : boolean, synchronous? : boolean): void; 59 | declare function nlapiGetFieldValues(fldnam : string): string[]; 60 | declare function nlapiSetFieldValues(fldnam : string, values : string[], firefieldchanged? : boolean, synchronous? : boolean): void; 61 | declare function nlapiGetFieldTexts(fldnam : string): string[]; 62 | declare function nlapiSetFieldTexts(fldnam :string, texts:string[], firefieldchanged?:boolean, synchronous?:boolean): void; 63 | declare function nlapiGetMatrixValue(type :string, fldnam :string, column :string) : string; 64 | declare function nlapiSetMatrixValue(type :string, fldnam :string, column :string, value :string, firefieldchanged? :boolean, synchronous?:boolean): void; 65 | declare function nlapiGetCurrentLineItemMatrixValue(type :string, fldnam :string, column :string) : string; 66 | declare function nlapiSetCurrentLineItemMatrixValue(type :string, fldnam :string, column :string, value :string, firefieldchanged?:boolean, synchronous?:boolean) : string; 67 | declare function nlapiGetLineItemMatrixValue(type :string, fldnam :string, linenum:number, column :string) : string; 68 | declare function nlapiGetLineItemValue(type : string, fldnam : string, linenum : number): string; 69 | declare function nlapiSetLineItemValue(type : string, fldnam : string, linenum : number, value : string): void; 70 | declare function nlapiGetLineItemText(type : string, fldnam : string, linenum : number): string; 71 | declare function nlapiFindLineItemValue(type :string, fldnam :string, val :string): number; 72 | declare function nlapiFindLineItemMatrixValue(type :string, fldnam :string, column:number, val :string): void; 73 | declare function nlapiGetMatrixCount(type :string, fldnam :string): number; 74 | declare function nlapiGetLineItemCount(type :string): number; 75 | declare function nlapiInsertLineItem(type :string, line:number): void; 76 | declare function nlapiRemoveLineItem(type :string, line:number): void; 77 | declare function nlapiSetCurrentLineItemValue(type : string, fldnam :string, value :string, firefieldchanged? : boolean, synchronous? : boolean) : void; 78 | declare function nlapiSetCurrentLineItemValue(type : string, fldnam :string, value :number, firefieldchanged? : boolean, synchronous? : boolean) : void; 79 | declare function nlapiSetCurrentLineItemText(type : string, fldnam :string, txt :string, firefieldchanged? : boolean, synchronous? : boolean) : void; 80 | declare function nlapiGetCurrentLineItemValue(type :string, fldnam :string) : string; 81 | declare function nlapiGetCurrentLineItemText(type :string, fldnam :string) : string; 82 | declare function nlapiGetCurrentLineItemIndex(type :string): void; 83 | declare function nlapiSetLineItemDisabled(type :string, fldnam :string, disable:boolean, linenum:number): void; 84 | declare function nlapiDisableLineItemField(type : string, fldnam : string, val : boolean) : void; 85 | declare function nlapiGetFieldMandatory(fldnam :string): void; 86 | declare function nlapiGetLineItemMandatory(type :string, fldnam :string): void; 87 | declare function nlapiSetFieldMandatory(fldnam :string, mandatory:boolean): void; 88 | declare function nlapiSetLineItemMandatory(type :string, fldnam :string, mandatory:boolean): void; 89 | declare function nlapiSelectLineItem(type :string, linenum:number): void; 90 | declare function nlapiCommitLineItem(type :string): void; 91 | declare function nlapiCancelLineItem(type :string): void; 92 | declare function nlapiSelectNewLineItem(type :string): void; 93 | declare function nlapiRefreshLineItems(type :string): void; 94 | declare function nlapiInsertSelectOption(fldnam :string, value :string, text :string, selected:boolean): void; 95 | declare function nlapiRemoveSelectOption(fldnam :string, value :string): void; 96 | declare function nlapiInsertLineItemOption(type :string, fldnam :string, value :string, text:string, selected:boolean): void; 97 | declare function nlapiRemoveLineItemOption(type :string, fldnam :string, value :string): void; 98 | declare function nlapiIsLineItemChanged(type :string): boolean; 99 | declare function nlapiGetNewRecord(): nlobjRecord; 100 | declare function nlapiGetOldRecord(): nlobjRecord; 101 | declare function nlapiCreateError(code : string, details :string, suppressEmail? : boolean): nlobjError; 102 | declare function nlapiCreateForm(title : string, hideHeader? :boolean): nlobjForm; 103 | declare function nlapiCreateList(title: string, hideHeader? :boolean): nlobjList; 104 | declare function nlapiCreateAssistant(title: string, hideHeader:boolean): void; 105 | declare function nlapiLoadFile(id :string): nlobjFile; 106 | declare function nlapiSubmitFile(file : nlobjFile): string; 107 | declare function nlapiDeleteFile(id: string): void; 108 | declare function nlapiCreateFile(name: string, type :string, contents: string): nlobjFile; 109 | declare function nlapiMergeRecord(id : string, baseType : string, baseId : string, altType? : string, altId? : string, fields? :Object): nlobjFile; 110 | declare function nlapiPrintRecord(type : string, id : string, format : string, properties?:Object): nlobjFile; 111 | declare function nlapiXMLToPDF(input:string): nlobjFile; 112 | declare function nlapiCreateTemplateRenderer() : nlobjTemplateRenderer; 113 | declare function nlapiCreateEmailMerger(templateId:string) : nlobjEmailMerger; 114 | declare function nlapiLogExecution(type : string, title : string, details? : any): void; 115 | declare function nlapiScheduleScript(script :string , deployment :string, parameters? : any):string; 116 | declare function nlapiOutboundSSO(ssoAppKey:string): void; 117 | declare function nlapiLoadConfiguration(type :string): nlobjConfiguration; 118 | declare function nlapiSubmitConfiguration(setup:nlobjConfiguration): void; 119 | declare function nlapiStringToDate(str : string, format? : string): Date; 120 | declare function nlapiDateToString(d: Date, formattype? : string): string; 121 | declare function nlapiAddDays(d:Date, days:number): Date; 122 | declare function nlapiAddMonths(d:Date, months:number): Date; 123 | declare function nlapiFormatCurrency(str:string): string; 124 | declare function nlapiEncrypt(s:string, algo?:string, key?:string): string; 125 | declare function nlapiEscapeXML(text : string): string; 126 | declare function nlapiStringToXML(str : string): Node; 127 | declare function nlapiXMLToString(xml : Node): string; 128 | declare function nlapiSelectValue(node :Node, xpath : string): string; 129 | declare function nlapiSelectValues(node:Node, path : string): string []; 130 | declare function nlapiSelectNode(node:Node, path : string): Node; 131 | declare function nlapiSelectNodes(node:Node, path : string): Node[]; 132 | declare function nlapiExchangeRate(fromCurrency :string, toCurrency :string, date:string): void; 133 | declare function nlapiInitiateWorkflow(recordtype :string, id :string, workflowid :string): void; 134 | declare function nlapiTriggerWorkflow(recordtype :string, id :string, workflowid :string, actionid :string): void; 135 | declare function nlapiCreateCurrentLineSubrecord(type :string, fldnam :string): void; 136 | declare function nlapiEditCurrentLineItemSubrecord(type :string, fldnam :string): void; 137 | declare function nlapiRemoveCurrentLineItemSubrecord(type :string, fldnam :string): void; 138 | declare function nlapiViewCurrentLineItemSubrecord(type :string, fldnam :string): void; 139 | declare function nlapiViewLineItemSubrecord(type :string, fldnam :string, linenum:number): void; 140 | declare function nlapiDisableField(fldnam: string, disabled: boolean) : void; 141 | declare function createSubrecord(fldnam :string): void; 142 | declare function editSubrecord(fldnam :string): void; 143 | declare function removeSubrecord(fldnam :string): void; 144 | declare function viewSubrecord(fldnam :string): void; 145 | 146 | /* 147 | function nlobjRecord(): void; 148 | function nlobjConfiguration(): void; 149 | function nlobjFile(): void; 150 | function nlobjSearchResult(): void; 151 | function nlobjContext(): void; 152 | function nlobjError(): void; 153 | function nlobjServerResponse(): void; 154 | function nlobjPortlet(): void; 155 | function nlobjList(): void; 156 | function nlobjForm(): void; 157 | function nlobjAssistant(): void; 158 | function nlobjField(): void; 159 | function nlobjSubList(): void; 160 | function nlobjColumn(): void; 161 | function nlobjTab(): void; 162 | function nlobjAssistantStep(): void; 163 | function nlobjFieldGroup(): void; 164 | function nlobjButton(): void; 165 | function nlobjSelectOption(): void; 166 | */ 167 | 168 | interface yieldResult {status: string; reason : string; size : number; information : string; } 169 | interface serverSubmitRecordFlags {disabletriggers:boolean; enablesourcing?:boolean; ignoremandatoryfields?:boolean;} 170 | interface serverSubmitFieldFlags {disabletriggers:boolean; enablesourcing?:boolean;} 171 | interface clientSubmitRecordFlags {disableTriggers:boolean; enableSourcing?:boolean; ignoreMandatoryfields?:boolean;} 172 | interface clientSubmitFieldFlags {disableTriggers:boolean; enableSourcing?:boolean;} 173 | 174 | declare function nlapiYieldScript() : yieldResult; 175 | declare function nlapiSetRecoveryPoint() : yieldResult; 176 | 177 | declare function nlapiCreateCSVImport():nlobjCSVImport; 178 | declare function nlapiSubmitCSVImport(impt:nlobjCSVImport):string; 179 | 180 | interface nlobjError{ 181 | getCode() : string; 182 | getDetails() : string; 183 | getId() : string; 184 | getInternalId() : number; 185 | getStackTrace() : string[]; 186 | getUserEvent() : string; 187 | } 188 | 189 | interface nlobjFile{ 190 | getDescription() : string; 191 | getFolder() : string; 192 | getId() : string; 193 | getName() : string; 194 | getSize() : number; 195 | getType() : string; 196 | getURL() : string; 197 | getValue() : string; 198 | isInactive() : boolean; 199 | isOnline() : boolean; 200 | setDescription(description : string) : void; 201 | setEncoding(encodingType : string) : void; 202 | setFolder(id : string) : void; 203 | setIsInactive(inactive : boolean) : void; 204 | setIsOnline(online: boolean) : void; 205 | setName(name: string) : void; 206 | } 207 | 208 | interface nlobjConfiguration{ 209 | getAllFields() :string[]; 210 | getField(fldnam:string):nlobjField; 211 | getFieldText(name:string):string; 212 | getFieldTexts(name:string):string[]; 213 | getFieldValue(name:string):string; 214 | getFieldValues(name:string):string[]; 215 | getType():string; 216 | setFieldText(name:string, text:string):void; 217 | setFieldTexts(name:string, text:string[]):void; 218 | setFieldValue(name:string, value:string):void; 219 | setFieldValues(name:string, value:string[]):void; 220 | } 221 | 222 | interface nlobjCSVImport{ 223 | setLinkedFile(sublist:string, file:string):void; 224 | setMapping(savedImport:string):void; 225 | setOption(option:string, value:string):void; 226 | setPrimaryFile(file:string):void; 227 | setPrimaryFile(file:nlobjFile):void; 228 | setQueue(queueNum:string):void; 229 | } 230 | 231 | declare class nlobjSearchColumn{ 232 | constructor(name : string, join? :string, summary?: string); 233 | 234 | getFormula() : string; 235 | getFunction() : string; 236 | getJoin() : string; 237 | getLabel() : string; 238 | getName() : string; 239 | getSort() : string; 240 | getSummary() : string; 241 | setFormula(formula : string) : nlobjSearchColumn; 242 | setFunction(functionid : string) : nlobjSearchColumn; 243 | setLabel(label : string) : nlobjSearchColumn; 244 | setSort(order? : boolean) : nlobjSearchColumn; 245 | setWhenOrderedBy(name : string, join : string) : nlobjSearchColumn; 246 | } 247 | declare class nlobjSearchFilter{ 248 | constructor(name : string, join:string, operator:string, value?:string, value2?:string, leftParens? : number, rightParens? : number, useOr? :boolean, useNot? : boolean); 249 | constructor(name : string, join:string, operator:string, value?:string[], leftParens? : number, rightParens? : number, useOr? :boolean, useNot? : boolean); 250 | constructor(name : string, join:string, operator:string, value?:number, value2?:number, leftParens? : number, rightParens? : number, useOr? :boolean, useNot? : boolean); 251 | getFormula() : string; 252 | getJoin() : string; 253 | getName() : string; 254 | getSummaryType() : string; 255 | getOperator() : string; 256 | setFormula(formula : string) : nlobjSearchFilter; 257 | setSummaryType(type : string) : nlobjSearchFilter; 258 | } 259 | 260 | interface nlobjSearchResultSet{ 261 | forEachResult(callback:(res:nlobjSearchResult) => boolean):void; 262 | getColumns() : nlobjSearchColumn[]; 263 | getResults(start : number, end : number) : nlobjSearchResult[]; 264 | } 265 | 266 | interface nlobjSearch{ 267 | 268 | addColumn(column : nlobjSearchColumn) : void; 269 | addColumns(columns : nlobjSearchColumn[]): void; 270 | addFilter(filter : nlobjSearchFilter) : void; 271 | addFilters(filters : nlobjSearchFilter[]) : void; 272 | deleteSearch() : void; 273 | getColumns() : nlobjSearchColumn[]; 274 | getFilterExpression() : Object[]; 275 | getFilters() :nlobjSearchFilter[]; 276 | getId() : string; 277 | getIsPublic() : boolean; 278 | getScriptId() : string; 279 | getSearchType() :string; 280 | runSearch() : nlobjSearchResultSet; 281 | saveSearch(title? :string, scriptId? :string) : string; 282 | setColumns(columns : nlobjSearchColumn[]) : void; 283 | setFilterExpression(filterExpression : Object[]) : void; 284 | setFilters(filters : nlobjSearchFilter[]):void; 285 | setIsPublic(type : boolean) : void; 286 | setRedirectURLToSearch(type : string, subtype : string, id? : string, pagemode? : boolean, parameters? : Object) : void; 287 | setRedirectURLToSearchResults(type : string, subtype : string, id? : string, pagemode? : boolean, parameters? : Object) : void; 288 | } 289 | 290 | interface nlobjSelectOption{ 291 | getId() : number; 292 | getText() : string; 293 | } 294 | 295 | interface nlobjField{ 296 | 297 | addSelectOption(value : string, text : string, selected?:boolean) : void; 298 | getLabel() : string; 299 | getName() : string; 300 | getSelectOptions(filter? : string, filteroperator? : string) : nlobjSelectOption[]; 301 | getType() : string; 302 | setAlias(alias : string) : nlobjField; 303 | setBreakType(breaktype : string) : nlobjField; 304 | setDefaultValue(value : string) : nlobjField; 305 | setDisplaySize(width : number, height? : number) : nlobjField; 306 | setDisplayType(type : string) : nlobjField; 307 | setHelpText(help : string, inline? : boolean) : nlobjField; 308 | setLabel(label : string) : nlobjField; 309 | setLayoutType(type : string, breaktype : string) : nlobjField; 310 | setLinkText(text : string) : nlobjField; 311 | setMandatory(mandatory : boolean) : nlobjField; 312 | setMaxLength(maxlength : number) : nlobjField; 313 | setPadding(padding : number) : nlobjField; 314 | } 315 | 316 | interface nlobjButton{ 317 | setDisabled(disabled:boolean):void; 318 | setLabel(label:string):void; 319 | setVisible(visible:boolean):void ; 320 | } 321 | 322 | 323 | interface nlobjFieldGroup{ 324 | setCollapsible(collapsible:boolean, hidden:boolean):void; 325 | setLabel(label:string):void; 326 | setShowBorder(show:boolean):void; 327 | setSingleColumn(column:boolean):void; 328 | } 329 | 330 | interface nlobjSubList{ 331 | 332 | addButton(name : string, label : string, script? : string) : nlobjButton; 333 | addField(name : string, type : string, label? : string, source? : string, fieldGroup?:string) : nlobjField; 334 | addMarkAllButtons() : void; 335 | addRefreshButton() : nlobjButton; 336 | getLineItemCount(group) : number; 337 | getLineItemValue(group, fldnam :string, linenum:number) : string; 338 | setAmountField(field : string); 339 | setDisplayType(type : string); 340 | setHelpText(help : string); 341 | setLabel(label : string); 342 | setLineItemValue(name : string, linenum : number,value : string); 343 | setLineItemValues(values: any[]); 344 | setUniqueField(name : string); 345 | } 346 | interface nlobjForm{ 347 | 348 | addButton(name : string, label : string, script? : string) : nlobjButton; 349 | addCredentialField(id : string, label : string, website? : string, scriptId? : string, value? : string, entityMatch? : boolean, tab? : string) : nlobjField; 350 | addField(name : string, type : string, label? : string, sourceOrRadio? : string, tab? : string) : nlobjField; 351 | addFieldGroup(name : string, label : string, tab? : string) : nlobjFieldGroup; 352 | addPageLink(type :string, title, url); 353 | addResetButton(label); 354 | addSubList(name : string, type : string, labe? : string, tab? : string) : nlobjSubList; 355 | addSubmitButton(label); 356 | addSubTab(name, label, tab); 357 | addTab(name, label); 358 | getButton(name); 359 | getField(name, radio?) : nlobjField; 360 | getSubList(name) : nlobjSubList; 361 | getSubTab(name); 362 | getTab(name); 363 | getTabs(); 364 | insertField(field, nextfld); 365 | insertSubList(sublist, nextsub); 366 | insertSubTab(subtab, nextsub); 367 | insertTab(tab, nexttab); 368 | removeButton(name); 369 | setFieldValues(values); 370 | setScript(script); 371 | setTitle(title) ; 372 | } 373 | 374 | interface nlobjRecord{ 375 | 376 | commitLineItem(group : string); 377 | createCurrentLineItemSubrecord(sublist : string, fldname : string); 378 | createSubrecord(fldname : string); 379 | editCurrentLineItemSubrecord(sublist : string, fldname : string); 380 | getCurrentLineItemValues(type : string, fldname : string) : string[]; 381 | editSubrecord(fldname : string); 382 | findLineItemMatrixValue(group : string, fldnam : string, column : string, val : string); 383 | findLineItemValue(group : string, fldnam : string, value : string) : number; 384 | getAllFields(); 385 | getAllLineItemFields(group : string); 386 | getCurrentLineItemMatrixValue(group : string, fldnam : string, column : string) : string; 387 | getField(fldnam : string) : nlobjField; 388 | getFieldText(name : string) : string; 389 | getFieldTexts(name : string) : string[]; 390 | getFieldValue(name : string) : string; 391 | getFieldValues(name : string) : string[]; 392 | getId() : string; 393 | getCurrentLineItemValue(type : string, fldnam : string) : string; 394 | getCurrentLineItemValues(type : string, fldnam : string) : string[]; 395 | getLineItemCount(group : string) : number; 396 | getLineItemField(group : string, fldnam : string, linenum : number) : nlobjField; 397 | getLineItemMatrixField(group : string, fldnam : string, linenum : number, column : string) : nlobjField; 398 | getLineItemMatrixValue(group : string, fldnam : string, lineum : number, column : string) : string; 399 | getLineItemText(group : string, fldnam : string, linenum : number) : string; 400 | getLineItemValue(group, name, linenum:number) : string; 401 | getLineItemValues(type :string, fldname, linenum:number) : string[]; 402 | getMatrixCount(group, fldnam :string) : number; 403 | getMatrixField(group, fldname, column); 404 | getMatrixValue(group, fldnam :string, column); 405 | getRecordType() : string; 406 | insertLineItem(group, linenum:number); 407 | removeLineItem(group, linenum:number); 408 | removeCurrentLineItemSubrecord(sublist, fldname); 409 | removeSubrecord(fldname); 410 | selectLineItem(group : string, linenum:number); 411 | selectNewLineItem(group); 412 | setCurrentLineItemMatrixValue(group, fldnam :string, column, value :string); 413 | setCurrentLineItemValue(group : string, fldnam :string, value :string, firefieldchanged? : boolean, synchronous? : boolean) : void; 414 | setCurrentLineItemValue(group : string, fldnam :string, value :number, firefieldchanged? : boolean, synchronous? : boolean) : void; 415 | removeLineItem(group: string, linenumber: number, ignoreRecalc ? : boolean); 416 | commitLineItem(group : string, ignoreRecalc? : boolean); 417 | setFieldText(name :string, text :string); 418 | setFieldTexts(name :string, text :string); 419 | setFieldValue(name :string, value :string); 420 | setFieldValues(name :string, value :string); 421 | setDateTimeValue(name :string, value :string, tz:string|number); 422 | setLineItemValue(group :string, name :string, linenum :number, value :string); 423 | setMatrixValue(group, fldnam :string, column :string, value :string); 424 | viewCurrentLineItemSubrecord(sublist :string, fldname :string); 425 | viewLineItemSubrecord(sublist :string, fldname :string, linenum :number); 426 | viewSubrecord(fldname :string); 427 | 428 | 429 | } 430 | 431 | interface nlobjSearchResult{ 432 | getAllColumns() : nlobjSearchColumn[]; 433 | getId() : string; 434 | getRecordType() : string; 435 | getText(column : nlobjSearchColumn) : string; 436 | getText(name : string, join? : string, summary? : string) : string; 437 | getValue(name : string, join? : string, summary? : string) : string; 438 | getValue(column : nlobjSearchColumn) : string; 439 | } 440 | 441 | interface nlobjRequest{ 442 | getParameter( name : string) : string; 443 | getParameterValues( name : string ) : string[]; 444 | getAllParameters() : string[]; 445 | getLineItemValue( group : string, name : string, line : number ) : string; 446 | getLineItemCount( group : string ) : number; 447 | getHeader( name: string ):string; 448 | getAllHeaders: any; 449 | getFile() : nlobjFile; 450 | getAllFiles() : nlobjFile[]; 451 | getBody() : string; 452 | getURL() :string; 453 | getMethod() :string; 454 | } 455 | 456 | interface nlobjResponse { 457 | addHeader(name : string, value : string) : void; 458 | getAllHeaders() : any; 459 | getBody() : string; 460 | getCode() : string; 461 | getError() : nlobjError; 462 | getHeader(name : string) : string; 463 | getHeaders(name : string) : string[]; 464 | setContentType(type : string, name? : string, disposition? : string) :void; 465 | setHeader(name : string, value : string) : void; 466 | sendRedirect(type : string, identifier : string, id? : string, editmode? : boolean, parameters? : any) : void; 467 | write(output : any) : void; 468 | writeLine(output : string) : void; 469 | writePage(pageobject : any) : void; 470 | } 471 | 472 | interface nlobjColumn{ 473 | addParamToURL(param: string, value: string, dynamic?:boolean) : void; 474 | setLabel(label:string) : void; 475 | setURL(url: string, dynamic?:boolean) : void; 476 | } 477 | 478 | interface nlobjList{ 479 | 480 | 481 | addButton(name:string, label:string, script?:string):void; 482 | addColumn(name:string, type:string, label:string, align?:string) : nlobjColumn; 483 | addEditColumn(column:nlobjColumn, showView?:boolean, showHrefCol?:boolean); 484 | addPageLink(type:string, title:string, url:string):void; 485 | 486 | addRow(row:Object):void; 487 | addRow(row:nlobjSearchResult):void; 488 | 489 | addRows(row:Object[]):void; 490 | addRows(row:nlobjSearchResult[]):void; 491 | 492 | 493 | setScript(script:string) :void; 494 | 495 | setStyle(style:string) :void; 496 | 497 | setTitle(title:string) : void; 498 | 499 | } 500 | 501 | interface nlobjContext { 502 | 503 | getColorPreferences() : {buttonbackground : string; 504 | text : string; 505 | portlet : string; 506 | portletlabel : string; 507 | crumbtext : string; 508 | inactivetab : string; 509 | link : string; 510 | backgroundrequiredfld : string; 511 | inactivetextontab : string; 512 | textontab : string; 513 | bodybackground : string; 514 | headbackground : string; 515 | shadedbackground : string; 516 | headerbar : string; 517 | shadedborder : string; 518 | activetab : string; 519 | }; 520 | getCompany() : string; 521 | getDepartment() : string; 522 | getDeploymentId() : string; 523 | getEmail() : string; 524 | getEnvironment() : string; 525 | getExecutionContext() : string; 526 | getFeature(name : string) : boolean; 527 | getLocation() : number; 528 | getLogLevel() : string; 529 | getName() : string; 530 | getPercentComplete() : number; 531 | getPermission(name : string) : number; 532 | getPreference(name : string) : string; 533 | getQueueCount() : number; 534 | getRemainingUsage() : number; 535 | getRole() : string; 536 | getRoleCenter() : string; 537 | getRoleId() : string; 538 | getScriptId() : string; 539 | getSessionObject(name : string) : any; 540 | getSetting(type : string, name : string) : string; 541 | getSubsidiary() : number; 542 | getUser() : string; 543 | getVersion() : string; 544 | setPercentComplete(pct :number) : void; 545 | setPercentComplete(pct :string) : void; 546 | setSessionObject(name : string, value : any) :void; 547 | setSetting(type : string, name : string, value : string) : void; 548 | 549 | } 550 | 551 | interface nlobjTemplateRenderer{ 552 | setTemplate(templateBody : string) : void; 553 | addRecord(varName:string, record:nlobjRecord) : void; 554 | addSearchResults(varName:string, resultSet: nlobjSearchResult[]) :void; 555 | renderToString() : string; 556 | renderToResponse(resp:nlobjResponse) : void; 557 | } 558 | 559 | interface nlobjEmailMerger { 560 | setCustomeRecord(recordType: string, recordId:string) : void; 561 | setEntity(entityType: string, entityId: string) : void; 562 | setRecipient(recipientType: string, recipientId: string) : void; 563 | setSupportCase(caseId: string) : void; 564 | setTransaction(transactionId: string) : void; 565 | merge() : nlobjMergeResult; 566 | } 567 | 568 | interface nlobjMergeResult{ 569 | getBody() : string; 570 | getSubject() : string; 571 | } 572 | 573 | --------------------------------------------------------------------------------