Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.

Search summary support #41

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a670a76
Fix typo
Sep 2, 2015
368572a
UpsertRequest.prototype.loadOrInitializeRecord should return a record…
Sep 2, 2015
a2b3ae7
Remove companyname from custome record if there is no changes made to…
Sep 3, 2015
7600a7d
Add subrecord to support customer addressbook
Sep 3, 2015
2b5b058
Remove this.record set to NULL
May 2, 2016
4f95d42
Fixing reply_list
May 3, 2016
05dec14
added support for joins on the filter columns, but:
hayden-t Apr 21, 2017
0a0a6ad
added backwards compatibility
hayden-t Apr 21, 2017
a465a7a
make lower bounds parameter optional
hayden-t Apr 21, 2017
1a98034
make lower bound parameter optional
hayden-t Apr 21, 2017
43e5699
Search sorting by custom column
hayden-t Apr 22, 2017
741ca8c
limit results to 1000 (1 page) when custom sorting
hayden-t Apr 23, 2017
6f5c75f
Column Label and Join Grouping Support
hayden-t Apr 23, 2017
c7923b3
Column Label and Join Grouping Support
hayden-t Apr 23, 2017
d52904e
support for column values having Text and Value
hayden-t Apr 23, 2017
2614c3d
camel case for internalId
hayden-t Apr 24, 2017
15320c9
brought up to speed with changes in search.js
hayden-t Apr 24, 2017
32e430d
typo breaks transform, fixed
hayden-t Apr 24, 2017
2d66d40
getLineItemValue incorrect field order, breaks.
hayden-t Apr 24, 2017
0ecdfdd
added test/error for transform record type lower case
hayden-t Apr 24, 2017
4b86b02
Merge pull request #1 from wildkatana/fix-upsert
hayden-t Apr 25, 2017
4ebaa8c
upsert create item sublist avoid SSS_INVALID_SUBLIST_OPERATION
hayden-t Apr 25, 2017
09a252a
exposes the nlapiSubmitRecord doSourcing and ignoreMandatoryFields
hayden-t May 24, 2017
11e39a8
Merge pull request #2 from hayden-t/search-filter-join-support
hayden-t Aug 12, 2022
944e91c
Merge pull request #3 from hayden-t/search-lower-bound-optional
hayden-t Aug 12, 2022
667bb5b
Merge pull request #4 from hayden-t/search-column-sort-fix
hayden-t Aug 12, 2022
be9e8c3
Merge pull request #5 from hayden-t/search-column-join-groups-and-labels
hayden-t Aug 12, 2022
2097ce1
Merge pull request #6 from hayden-t/transform-bug-fixes
hayden-t Aug 12, 2022
e06a995
Merge pull request #7 from hayden-t/upsert-bug-fixes
hayden-t Aug 12, 2022
b24106f
Merge pull request #8 from hayden-t/upsert-expose-ignoremandatory
hayden-t Aug 12, 2022
110328a
Revert "Fix typo"
hayden-t Aug 12, 2022
6a0a9c2
Revert "Remove companyname from custome record if there is no changes…
hayden-t Aug 12, 2022
e2da1fc
Revert "UpsertRequest.prototype.loadOrInitializeRecord should return …
hayden-t Aug 12, 2022
affaa57
add in changes from my main for no conflict merge
hayden-t Aug 12, 2022
f418d29
Merge branch 'master' into wafendy-merge
hayden-t Aug 12, 2022
d4c5dce
Merge pull request #12 from hayden-t/wafendy-merge
hayden-t Aug 12, 2022
55e6d28
Update README.md
hayden-t Aug 12, 2022
81e4a69
saved search filter support
hayden-t Aug 12, 2022
8f42d33
Merge pull request #13 from hayden-t/saved-search-filters
hayden-t Aug 12, 2022
d12b1ee
summary supported, note, resultblock id and recordtype return null wh…
hayden-t Aug 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This readme has not been updated to reflect changes made by me, to see new features look at network graph/commit history - hayden

# rest_suite

Server-side Javascript library that wraps parts of the Netsuite SuiteScript API (v2010.1). This
Expand Down
149 changes: 129 additions & 20 deletions lib/netsuite_toolkit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/** @namespace NetsuiteToolkit */
var NetsuiteToolkit = {};
NetsuiteToolkit.RecordProcessor = {};
NetsuiteToolkit.SublistProcessor = {};
var NetsuiteToolkit = {};
NetsuiteToolkit.RecordProcessor = {};
NetsuiteToolkit.SublistProcessor = {};
NetsuiteToolkit.SubrecordProcessor = {};

var line_item_match_error = "Unable to find matching line item with the given field.";
var malformed_data_error = "Data for processing line items is malformed.";
Expand Down Expand Up @@ -90,6 +91,10 @@ NetsuiteToolkit.setFieldValue = function(record, field_name, value) {
record.setFieldValue(field_name, value);
}

NetsuiteToolkit.getFieldValue = function(record, field_name) {
return record.getFieldValue(field_name);
}

/**
* Fetches the line item count for a given NetSuite sublist.
*
Expand All @@ -114,8 +119,8 @@ NetsuiteToolkit.getLineItemCount = function(record, sublist_name) {
* @memberof NetsuiteToolkit
* @return {number} The value of the filed on the given sublist at the given index
*/
NetsuiteToolkit.getLineItemValue = function(record, sublist_name, index, field_name) {
return record.getLineItemValue(sublist_name, index, field_name);
NetsuiteToolkit.getLineItemValue = function(record, sublist_name, field_name, index) {
return record.getLineItemValue(sublist_name, field_name, index);
}

/**
Expand Down Expand Up @@ -162,6 +167,35 @@ NetsuiteToolkit.removeLineItem = function(record, sublist_name, index) {
record.removeLineItem(sublist_name, index);
}

NetsuiteToolkit.selectNewLineItem = function(record, sublist_name) {
record.selectNewLineItem(sublist_name);
}

NetsuiteToolkit.setCurrentLineItemValue = function(record, item, field, value) {
record.setCurrentLineItemValue(item, field, value);
}

NetsuiteToolkit.commitLineItem = function(record, item) {
record.commitLineItem(item);
}

NetsuiteToolkit.findLineItemValue = function(record, item, field, value) {
return record.findLineItemValue(item, field, value);
}

NetsuiteToolkit.selectLineItem = function(record, item, linenum) {
record.selectLineItem(item, linenum);
}

NetsuiteToolkit.createCurrentLineItemSubrecord = function(record, sublist, subrecord) {
return record.createCurrentLineItemSubrecord(sublist, subrecord);
}

NetsuiteToolkit.editCurrentLineItemSubrecord = function(record, sublist, subrecord) {
return record.editCurrentLineItemSubrecord(sublist, subrecord);
}


/**
* Removes a line item at a given index for a given sublist field.
*
Expand Down Expand Up @@ -305,6 +339,7 @@ NetsuiteToolkit.SublistProcessor = (function() {
this.create_list = sublist_data['create'] || [];
this.update_list = sublist_data['update'] || [];
this.excise_list = sublist_data['excise'] || [];
this.bySelect = sublist_data['bySelect'] || false;
}

/**
Expand Down Expand Up @@ -369,14 +404,39 @@ NetsuiteToolkit.SublistProcessor = (function() {
* @memberof NetsuiteToolkit.SublistProcessor
*/
SublistProcessor.prototype.createLineItem = function(creation_request) {


index = creation_request['index'];
data = creation_request['data'];

if(!index) {
index = NetsuiteToolkit.getLineItemCount(this.record, this.sublist_name);
}
NetsuiteToolkit.insertLineItem(this.record, this.sublist_name, index);
this.updateLineItemFields(index, data);
subrecord_request = creation_request['subrecord'];

if(!this.bySelect){
if(!index) {
index = NetsuiteToolkit.getLineItemCount(this.record, this.sublist_name);
}

if(this.sublist_name == 'addressbook') {
NetsuiteToolkit.selectNewLineItem(this.record, this.sublist_name );

for(field in data) {
value = data[field];
NetsuiteToolkit.setCurrentLineItemValue(this.record, this.sublist_name, field, value);
}

if(subrecord_request) {
subrecord_processor = new NetsuiteToolkit.SubrecordProcessor(this.record, this.sublist_name, subrecord_request);
subrecord_processor.processCreations();
}
NetsuiteToolkit.commitLineItem(this.record, this.sublist_name);
}else{//end address book
NetsuiteToolkit.insertLineItem(this.record, this.sublist_name, index);
this.updateLineItemFields(index, data);
}
}else{
this.record.selectNewLineItem(this.sublist_name)
this.updateLineItemFields(index, data);
this.record.commitLineItem(this.sublist_name)
}
}

/**
Expand All @@ -391,14 +451,21 @@ NetsuiteToolkit.SublistProcessor = (function() {
index = update_request['index'];
match = update_request['match'];
data = update_request['data'];

if(!index && !match) {
throw NetsuiteToolkit.SublistProcessor.UnableToMatch;
} else if(!index) {
index = this.matchLineItemByField(match, data);
subrecord_request = update_request['subrecord'];

if(this.sublist == 'addressbook') {
if(subrecord_request) {
subrecord_processor = new NetsuiteToolkit.SubrecordProcessor(this.record, this.sublist, subrecord_request);
subrecord_processor.processUpdates();
}
} else {
if(!index && !match) {
throw NetsuiteToolkit.SublistProcessor.UnableToMatch;
} else if(!index) {
index = this.matchLineItemByField(match, data);
}
this.updateLineItemFields(index, data);
}

this.updateLineItemFields(index, data);
};

/**
Expand Down Expand Up @@ -435,7 +502,8 @@ NetsuiteToolkit.SublistProcessor = (function() {
SublistProcessor.prototype.updateLineItemFields = function(index, line_item_data) {
for(field in line_item_data) {
value = line_item_data[field];
NetsuiteToolkit.setLineItemValue(this.record, this.sublist_name, field, index, value);
if(!this.bySelect)NetsuiteToolkit.setLineItemValue(this.record, this.sublist_name, field, index, value);
else this.record.setCurrentLineItemValue(this.sublist_name, field, value);
}
}

Expand Down Expand Up @@ -473,20 +541,60 @@ NetsuiteToolkit.SublistProcessor = (function() {
*/
SublistProcessor.prototype.compareLineItemValue = function(index, match_field, match_value) {
netsuite_value = NetsuiteToolkit.getLineItemValue(this.record, this.sublist_name,
index, match_field);
match_field, index);
return (netsuite_value == match_value);
}

return SublistProcessor;
})();

NetsuiteToolkit.SubrecordProcessor = (function() {
function SubrecordProcessor(record, sublist, subrecord_data) {
this.record = record;
this.sublist = sublist;
this.subrecord_name = subrecord_data['name'];
this.data = subrecord_data['data'];
this.match = subrecord_data['match'];
}

SubrecordProcessor.prototype.processCreations = function() {
var subrecord = NetsuiteToolkit.createCurrentLineItemSubrecord(this.record, this.sublist, this.subrecord_name);

for(field in this.data) {
value = this.data[field];
NetsuiteToolkit.setFieldValue(subrecord, field, value);
}
subrecord.commit();
}

SubrecordProcessor.prototype.processUpdates = function() {
var linenum = NetsuiteToolkit.findLineItemValue(this.record, this.sublist, this.match['field'], this.match['value']);

if(linenum && linenum > 0) {
NetsuiteToolkit.selectLineItem(this.record, this.sublist, linenum);
var subrecord = NetsuiteToolkit.editCurrentLineItemSubrecord(this.record, this.sublist, this.subrecord_name);

for(field in data) {
var value = data[field];
NetsuiteToolkit.setFieldValue(subrecord, field, value);
}
subrecord.commit();
} else {
throw NetsuiteToolkit.SubrecordProcessor.UnableToMatch;
}
}

return SubrecordProcessor;
})();

/**
* An exception thrown in the event that the sublist data given is malformed.
* @static
* @field
* @memberof NetsuiteToolkit.SublistProcessor
*/
NetsuiteToolkit.SublistProcessor.MalformedData = new Error(malformed_data_error);
NetsuiteToolkit.SubrecordProcessor.MalformedData = new Error(malformed_data_error);

/**
* An exception thrown in the event that a line item cannot be matched
Expand All @@ -496,6 +604,7 @@ NetsuiteToolkit.SublistProcessor.MalformedData = new Error(malformed_data_error)
* @memberof NetsuiteToolkit.SublistProcessor
*/
NetsuiteToolkit.SublistProcessor.UnableToMatch = new Error(line_item_match_error);
NetsuiteToolkit.SubrecordProcessor.UnableToMatch = new Error(line_item_match_error);

if(typeof(exports) != 'undefined') {
exports.NetsuiteToolkit = NetsuiteToolkit;
Expand Down
104 changes: 92 additions & 12 deletions lib/saved_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
this.SavedSearch = (function() {

/** @constructor */
function SavedSearch(recordType, searchId, lowerBound, batchSize) {
this.recordType = recordType;
function SavedSearch(recordType, searchId, lowerBound, batchSize, searchFilters) {

this.SEARCH_FILTER_NAME_KEY = 'name';
this.SEARCH_FILTER_OPERATOR_KEY = 'operator';
this.SEARCH_FILTER_VALUE_KEY = 'value';
this.SEARCH_FILTER_JOIN_KEY = 'join';

this.recordType = recordType;
this.searchId = searchId;
this.lowerBound = lowerBound;
this.lowerBoundFilterIndex = 0;
this.originalLowerBound = lowerBound;
this.originalBatchSize = batchSize;

Expand All @@ -22,15 +29,38 @@ this.SavedSearch = (function() {
intBatchSize = intBatchSize + (1000 - (intBatchSize % 1000));
}
this.batchSize = intBatchSize;

this.rawSearchFilters = searchFilters;

this.searchFilters = [];
this.searchColumns = [];
this.results = [];

this.createSearchFilter();
this.createSearchColumn();
this.createSearchFilters();
if(lowerBound && batchSize)this.generateLowerBoundFilter();
if(lowerBound && batchSize)this.createSearchColumn();
}


/**
* Iterates over `rawSearchFilters` calling generating an nlobjSearchFilter
* from each
*
* @method
* @memberof Searcher
* @return {null}
*/
SavedSearch.prototype.createSearchFilters = function() {
for(index in this.rawSearchFilters) {
searchFilterData = this.rawSearchFilters[index];
searchFilterObject = this.getSearchFilterObject(searchFilterData);

this.searchFilters.push(searchFilterObject);
}
this.lowerBoundFilterIndex = this.searchFilters.length;
}


/**
* Generates a new nlobjSearchFilter instance and adds it to the
* list of search filters
Expand All @@ -39,12 +69,34 @@ this.SavedSearch = (function() {
* @memberof SavedSearch
* @return {null}
*/
SavedSearch.prototype.createSearchFilter = function() {
this.searchFilters = []
filter = NetsuiteToolkit.searchFilter('internalidnumber', null,
'greaterthan', this.lowerBound);
this.searchFilters.push(filter);
SavedSearch.prototype.generateLowerBoundFilter = function() {
searchFilterData = {};
searchFilterData[this.SEARCH_FILTER_NAME_KEY] = 'internalidnumber';
searchFilterData[this.SEARCH_FILTER_OPERATOR_KEY] = 'greaterthan';
searchFilterData[this.SEARCH_FILTER_VALUE_KEY] = this.lowerBound;

lowerBoundFilterObject = this.getSearchFilterObject(searchFilterData)
this.searchFilters[this.lowerBoundFilterIndex] = lowerBoundFilterObject;
}
/**
* Generates an nlobjSearchFilter with the given params
*
* @method
* @param {object} searchFilterData The object representing the search filter params
* @memberof Searcher
* @return {nlobjSearchFilter} The generated search filter
*/
SavedSearch.prototype.getSearchFilterObject = function(searchFilterData) {
name = searchFilterData[this.SEARCH_FILTER_NAME_KEY];
operator = searchFilterData[this.SEARCH_FILTER_OPERATOR_KEY];
value = searchFilterData[this.SEARCH_FILTER_VALUE_KEY];
join = searchFilterData[this.SEARCH_FILTER_JOIN_KEY];
if (typeof join == 'undefined')join = null;

filter = NetsuiteToolkit.searchFilter(name, join, operator, value);
return filter;
}


/**
* Generates a new nlobjSearchColumn instance and adds it to the
Expand Down Expand Up @@ -134,7 +186,7 @@ this.SavedSearch = (function() {
SavedSearch.prototype.updateBoundAndFilter = function(resultsBlock) {
newLowerBound = this.extractLowerBound(resultsBlock);
this.lowerBound = newLowerBound;
this.createSearchFilter();
this.generateLowerBoundFilter();
}

/**
Expand All @@ -158,7 +210,35 @@ this.SavedSearch = (function() {
* @return {null}
*/
SavedSearch.prototype.appendResults = function(resultsBlock) {
this.results = this.results.concat(resultsBlock);
var newResultsBlock = [];
for ( var i = 0; resultsBlock != null && i < resultsBlock.length; i++ )
{
var newResult = {"id":resultsBlock[i].getId(), "recordtype":resultsBlock[i].getRecordType(), "columns":{}};
var result = resultsBlock[i];
var columns = result.getAllColumns();
var columnLen = columns.length;

for (x = 0; x < columnLen; x++)
{
var column = columns[x];
var name = column.getName();
var label = column.getLabel();
var join = column.getJoin();
var value = result.getValue(column);
var text = result.getText(column);
var joinTitle = join + 'Join';
var columnTitle = (label ? label : name);
if(text && (text !== value))var columnData = {'name':text, 'internalId':value};
else columnData = value;
if(join && !label){
if(!(joinTitle in newResult.columns))newResult.columns[joinTitle] = {};
newResult.columns[joinTitle][columnTitle] = columnData;
}
else newResult.columns[columnTitle] = columnData;
}
newResultsBlock.push(newResult);
}
this.results = this.results.concat(newResultsBlock);
}

/**
Expand Down Expand Up @@ -205,7 +285,7 @@ this.SavedSearch = (function() {
*/
var savedSearchPostHandler = function(request) {
var savedSearch = new SavedSearch(request['record_type'], request['search_id'],
request['lower_bound'], request['batch_size']);
request['lower_bound'], request['batch_size'],request['search_filters']);
savedSearch.executeSearch();
return savedSearch.reply();
}
Loading