Skip to content

Commit dd26347

Browse files
authored
Merge pull request #56 from oracle-samples/suiteworld2024
Suiteworld2024
2 parents fb98168 + cbb502e commit dd26347

File tree

88 files changed

+6013
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+6013
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SuiteWorld 2024 Code Samples
2+
3+
This directory contains code samples shared by presenters in the Developer Track breakout sessions of SuiteWorld 2024. Not all presentations are represented.
4+
5+
See https://suiteanswers.custhelp.com/app/answers/detail/a_id/1017116/loc/en_US for corresponding slide decks from the presentations. A NetSuite login is required.
6+
If this link does not work for you, log in to your NetSuite account and visit SuiteAnswers from Support > SuiteAnswers. Search "SuiteWorld," and you should find a result for SuiteWorld Presentations 2024.
7+
8+
## Disclaimer
9+
The sample code included herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations. Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto. Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
10+
11+
Samples in this directory are not fully tested or maintained and may not follow the same guidelines and practices as other samples provided in the NetSuite SuiteCloud Samples repository. We do not plan to address any issues or make updates to these samples but only provide them as they were presented. Only samples from presentations by Oracle employees are currently offered.
12+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- This file is used for hiding the content of your SuiteApp when deploying to a NetSuite account. -->
2+
<!-- The configuration below hides all content except for the files and objects specified under the apply tag. Use the commented lines as examples. -->
3+
<!-- This configuration is only applied when the "Apply Installation Preferences" option is provided through SuiteCloud SDK. Otherwise this file is ignored. -->
4+
<!-- For more information, see https://system.netsuite.com/app/help/helpcenter.nl?fid=section_1515950176.html -->
5+
6+
<preference type="HIDING" defaultAction="HIDE">
7+
<apply action="UNHIDE">
8+
<!-- <path>~/FileCabinet/SuiteApps/xxx.xxx.xxx/MyScript.js</path> -->
9+
</apply>
10+
</preference>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- This file is used for locking the content of your SuiteApp when deploying to a NetSuite account. -->
2+
<!-- The configuration below locks all content except for the files and objects specified under the apply tag. Use the commented lines as examples. -->
3+
<!-- This configuration is only applied when the "Apply Installation Preferences" option is provided through SuiteCloud SDK. Otherwise this file is ignored. -->
4+
<!-- For more information, see https://system.netsuite.com/app/help/helpcenter.nl?fid=section_1543865613.html -->
5+
6+
<preference type="LOCKING" defaultAction="LOCK">
7+
<apply action="UNLOCK">
8+
<!-- <object>custcontenttype_myobject</object> -->
9+
<!-- <path>~/FileCabinet/SuiteApps/xxx.xxx.xxx/MyScript.js</path> -->
10+
</apply>
11+
</preference>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- This file is used for overwriting or preserving the objects in your SuiteApp when deploying to a NetSuite account. -->
2+
<!-- This configuration is only applied when the "Apply Installation Preferences" option is provided through SuiteCloud SDK. Otherwise this file is ignored. -->
3+
<!-- For more information, see https://system.netsuite.com/app/help/helpcenter.nl?fid=section_160751417871.html -->
4+
5+
<preference type="OVERWRITING">
6+
<!-- SCRIPT DEPLOYMENTS -->
7+
<!-- The configuration below overwrites all scriptdeployments except for the ones specified with the action tag PRESERVE. -->
8+
<!-- <scriptdeployments defaultAction="OVERWRITE">
9+
<scriptdeployment scriptid="customscript_user_event_example.customdeploy_ue_example" action="PRESERVE" />
10+
</scriptdeployments> -->
11+
12+
<!-- CUSTOM RECORD TYPES -->
13+
<!-- The configuration below preserves all instances of customrecord_type_example except for the ones with the action tag OVERWRITE. -->
14+
<!-- <customrecordtypes>
15+
<customrecordtype scriptid="customrecord_type_example">
16+
<instances defaultAction="PRESERVE">
17+
<instance scriptid="customrecord_instance_example" action="OVERWRITE" />
18+
</instances>
19+
</customrecordtype>
20+
</customrecordtypes> -->
21+
22+
<!-- CUSTOM LISTS -->
23+
<!-- The configuration below overwrites all customvalues of customlist_example except for the ones with the action tag PRESERVE. -->
24+
<!-- <customlists>
25+
<customlist scriptid="customlist_example">
26+
<customvalues defaultAction="OVERWRITE">
27+
<customvalue scriptid="customlist_value_example" action="PRESERVE" />
28+
</customvalues>
29+
</customlist>
30+
</customlists> -->
31+
</preference>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
*@NApiVersion 2.1
3+
*@NScriptType MapReduceScript
4+
*/
5+
define(['N/query', 'N/record'], function(query, record) {
6+
/**
7+
* SuiteQL query which loads auto-purchase set up for items, stock of which is below set up limit.
8+
* Items, which are are below the limit, but are already ordered by some purchase order in processing
9+
* are excluded.
10+
*/
11+
const QUERY = "SELECT setup.custrecord_autopurch_vendor AS vendor, setup.custrecord_autopurch_item AS item, setup.custrecord_autopurch_quantity quantity "
12+
+ "FROM customrecord_autopurchase setup "
13+
+ "INNER JOIN item item ON setup.custrecord_autopurch_item = item.id "
14+
+ "WHERE nvl(item.totalQuantityOnHand, 0.0) <= setup.custrecord_autopurch_quantity "
15+
+ "AND NOT EXISTS("
16+
+ "SELECT 1 FROM TransactionLine tl, Transaction t "
17+
+ "WHERE t.id = tl.transaction "
18+
+ "AND t.type = 'PurchOrd' "
19+
+ "AND t.status IN ('PurchOrd:A', 'PurchOrd:B', 'PurchOrd:D', 'PurchOrd:E', 'PurchOrd:F', 'PurchOrd:G') "
20+
+ "AND tl.item = setup.custrecord_autopurch_item "
21+
+ "AND t.entity = setup.custrecord_autopurch_vendor"
22+
+")";
23+
24+
/**
25+
* @param {Object} context input context
26+
* @returns array of loaded auto-purchasing tuples (vendor, item, quantity).
27+
*/
28+
function getInputData(context) {
29+
let results = query.runSuiteQL({
30+
query: QUERY
31+
}).results;
32+
33+
let convertedResults = [];
34+
results.forEach((value) => {
35+
let valueAsMap = value.asMap();
36+
convertedResults.push(valueAsMap);
37+
});
38+
return convertedResults;
39+
}
40+
41+
/**
42+
* Transforms array of tuples from {@link getInputData} to pairs (key: vendor, value: original_tuple).
43+
* @param {Object} context
44+
*/
45+
function map(context) {
46+
let contextValue = JSON.parse(context.value);
47+
context.write({
48+
key: contextValue.vendor,
49+
value: contextValue
50+
});
51+
}
52+
53+
/**
54+
* Based on the auto-purchasing set up, for each vendor generates purchase order with list of items and quantities.
55+
* Result is written in context in form of key: vendor, value: created purchase order id
56+
* @param {Object} context
57+
*/
58+
function reduce(context) {
59+
let purchaseOrder = record.create({ type: 'purchaseorder' });
60+
purchaseOrder.setValue({ fieldId: 'entity', value: context.key });
61+
purchaseOrder.setValue({ fieldId: 'memo', value: 'Created as SW example' });
62+
context.values.forEach((value, index) => {
63+
let itemData = JSON.parse(value);
64+
purchaseOrder.setSublistValue({
65+
sublistId: 'item', fieldId: 'item', value: itemData.item, line: index
66+
});
67+
purchaseOrder.setSublistValue({
68+
sublistId: 'item', fieldId: 'quantity', value: itemData.quantity, line: index
69+
});
70+
});
71+
let purchaseOrderId = purchaseOrder.save();
72+
73+
context.write({
74+
key: context.key,
75+
value: purchaseOrderId
76+
});
77+
}
78+
79+
return {
80+
getInputData: getInputData,
81+
map: map,
82+
reduce: reduce
83+
};
84+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<entitycustomfield scriptid="custentity_vendor_autopurchase">
2+
<accesslevel>2</accesslevel>
3+
<appliestocontact>F</appliestocontact>
4+
<appliestocustomer>F</appliestocustomer>
5+
<appliestoemployee>F</appliestoemployee>
6+
<appliestogroup>F</appliestogroup>
7+
<appliestoothername>F</appliestoothername>
8+
<appliestopartner>F</appliestopartner>
9+
<appliestopricelist>F</appliestopricelist>
10+
<appliestoprojecttemplate>F</appliestoprojecttemplate>
11+
<appliestostatement>F</appliestostatement>
12+
<appliestovendor>T</appliestovendor>
13+
<appliestowebsite>F</appliestowebsite>
14+
<applyformatting>F</applyformatting>
15+
<availableexternally>F</availableexternally>
16+
<checkspelling>F</checkspelling>
17+
<defaultchecked>F</defaultchecked>
18+
<defaultselection></defaultselection>
19+
<defaultvalue></defaultvalue>
20+
<description></description>
21+
<displayheight></displayheight>
22+
<displaytype>NORMAL</displaytype>
23+
<displaywidth></displaywidth>
24+
<dynamicdefault></dynamicdefault>
25+
<encryptatrest>F</encryptatrest>
26+
<fieldtype>CHECKBOX</fieldtype>
27+
<globalsearch>F</globalsearch>
28+
<help></help>
29+
<isformula>F</isformula>
30+
<ismandatory>F</ismandatory>
31+
<isparent>F</isparent>
32+
<label>Allow Automatic Purchase</label>
33+
<linktext></linktext>
34+
<maxlength></maxlength>
35+
<maxvalue></maxvalue>
36+
<minvalue></minvalue>
37+
<onparentdelete></onparentdelete>
38+
<parentsubtab></parentsubtab>
39+
<searchcomparefield></searchcomparefield>
40+
<searchdefault></searchdefault>
41+
<searchlevel>2</searchlevel>
42+
<selectrecordtype></selectrecordtype>
43+
<showhierarchy>F</showhierarchy>
44+
<showinlist>F</showinlist>
45+
<sourcefilterby></sourcefilterby>
46+
<sourcefrom></sourcefrom>
47+
<sourcelist></sourcelist>
48+
<storevalue>T</storevalue>
49+
<subtab>[scriptid=custtab_vend_autopurch_tab]</subtab>
50+
</entitycustomfield>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<itemcustomfield scriptid="custitem_ii_autopurchase">
2+
<accesslevel>2</accesslevel>
3+
<appliestogroup>F</appliestogroup>
4+
<appliestoinventory>T</appliestoinventory>
5+
<appliestokit>F</appliestokit>
6+
<appliestononinventory>F</appliestononinventory>
7+
<appliestoothercharge>F</appliestoothercharge>
8+
<appliestopricelist>F</appliestopricelist>
9+
<appliestoservice>F</appliestoservice>
10+
<appliestospecificitems>F</appliestospecificitems>
11+
<appliestosubplan>F</appliestosubplan>
12+
<applyformatting>F</applyformatting>
13+
<checkspelling>F</checkspelling>
14+
<defaultchecked>F</defaultchecked>
15+
<defaultselection></defaultselection>
16+
<defaultvalue></defaultvalue>
17+
<description></description>
18+
<displayheight></displayheight>
19+
<displaytype>NORMAL</displaytype>
20+
<displaywidth></displaywidth>
21+
<dynamicdefault></dynamicdefault>
22+
<encryptatrest>F</encryptatrest>
23+
<fieldtype>CHECKBOX</fieldtype>
24+
<globalsearch>F</globalsearch>
25+
<help></help>
26+
<includechilditems>F</includechilditems>
27+
<isformula>F</isformula>
28+
<ismandatory>F</ismandatory>
29+
<isparent>F</isparent>
30+
<itemmatrix>F</itemmatrix>
31+
<itemsubtype>PURCHASE</itemsubtype>
32+
<label>Allow Automatic Purchase</label>
33+
<linktext></linktext>
34+
<maxlength></maxlength>
35+
<maxvalue></maxvalue>
36+
<minvalue></minvalue>
37+
<onparentdelete></onparentdelete>
38+
<parentsubtab></parentsubtab>
39+
<searchcomparefield></searchcomparefield>
40+
<searchdefault></searchdefault>
41+
<searchlevel>2</searchlevel>
42+
<selectrecordtype></selectrecordtype>
43+
<showhierarchy>F</showhierarchy>
44+
<showinlist>F</showinlist>
45+
<sourcefilterby></sourcefilterby>
46+
<sourcefrom></sourcefrom>
47+
<sourcelist></sourcelist>
48+
<storevalue>T</storevalue>
49+
<subtab>[scriptid=custtab_ii_autopurch_tab]</subtab>
50+
</itemcustomfield>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<itemcustomfield scriptid="custitem_ii_lowerlimit">
2+
<accesslevel>2</accesslevel>
3+
<appliestogroup>F</appliestogroup>
4+
<appliestoinventory>T</appliestoinventory>
5+
<appliestokit>F</appliestokit>
6+
<appliestononinventory>F</appliestononinventory>
7+
<appliestoothercharge>F</appliestoothercharge>
8+
<appliestopricelist>F</appliestopricelist>
9+
<appliestoservice>F</appliestoservice>
10+
<appliestospecificitems>F</appliestospecificitems>
11+
<appliestosubplan>F</appliestosubplan>
12+
<applyformatting>T</applyformatting>
13+
<checkspelling>F</checkspelling>
14+
<defaultchecked>F</defaultchecked>
15+
<defaultselection></defaultselection>
16+
<defaultvalue></defaultvalue>
17+
<description></description>
18+
<displayheight></displayheight>
19+
<displaytype>NORMAL</displaytype>
20+
<displaywidth></displaywidth>
21+
<dynamicdefault></dynamicdefault>
22+
<encryptatrest>F</encryptatrest>
23+
<fieldtype>FLOAT</fieldtype>
24+
<globalsearch>F</globalsearch>
25+
<help></help>
26+
<includechilditems>F</includechilditems>
27+
<isformula>F</isformula>
28+
<ismandatory>F</ismandatory>
29+
<isparent>F</isparent>
30+
<itemmatrix>F</itemmatrix>
31+
<itemsubtype>PURCHASE</itemsubtype>
32+
<label>Auto-purchase When Below</label>
33+
<linktext></linktext>
34+
<maxlength></maxlength>
35+
<maxvalue></maxvalue>
36+
<minvalue></minvalue>
37+
<onparentdelete></onparentdelete>
38+
<parentsubtab></parentsubtab>
39+
<searchcomparefield></searchcomparefield>
40+
<searchdefault></searchdefault>
41+
<searchlevel>2</searchlevel>
42+
<selectrecordtype></selectrecordtype>
43+
<showhierarchy>F</showhierarchy>
44+
<showinlist>F</showinlist>
45+
<sourcefilterby></sourcefilterby>
46+
<sourcefrom></sourcefrom>
47+
<sourcelist></sourcelist>
48+
<storevalue>T</storevalue>
49+
<subtab>[scriptid=custtab_ii_autopurch_tab]</subtab>
50+
</itemcustomfield>

0 commit comments

Comments
 (0)