NotesViewEntry sort items - lotus-notes

I have following code in the data binding of a data table. I would like to sort the items (viewEntries) on part (spareProductPart) in order to display them sorted in my data table.
var thisDb:NotesDatabase = sessionAsSigner.getDatabase("","demo/demo.nsf");
Ventry=function(ve:NotesViewEntry){
this.prod=entry.getDocument().getItemValueString("spareProduct");
this.drawing=entry.getDocument().getItemValueString("spareDrawingNumber");
this.part=entry.getDocument().getItemValueString("spareProductPart");
this.unid=entry.getUniversalID();
etc ....
}
var viewEntries=[];
var Collection:NotesViewEntryCollection=thisDb.getView("parts").getAllEntries();
Collection.FTSearch(viewScope.toSearch);
var entry:NotesViewEntry=Collection.getFirstEntry();
while (entry!=null){ //loop over all entryes
viewEntries.push( new Ventry( entry) )
entry = Collection.getNextEntry();
}
return (viewEntries);

Use NotesView's FTSearchSorted instead of FTSearch.
Your code would look like this then:
...
var viewEntries = [];
var viewParts:NotesView = thisDb.getView("parts");
viewParts.FTSearchSorted(viewScope.toSearch, 0, "yourSortedColumnName");
var Collection:NotesViewEntryCollection = viewParts.getAllEntries();
var entry:NotesViewEntry = Collection.getFirstEntry();
...

"This class provides you mainly with a collection of documents in a view-sorted order." That means if you want your viewEntryCollection sorted by the part number, your view would have to be sorted that way. So the answer: change the view so that it's sorted by by spareProductPart

Related

Merge two diffrent json in one json

I have two json arrays like
var json1 = [{"city":"Ahmedabad"}]
var json2 = [{"State":"Gujarat"}]
I want them merge in to single arrays
var finalObj = [{"city":"Ahmedabad","State":"Gujarat"}]
If you are using concat() method then the arrays will get merged not the elements then you will get an output somewhat like
[{"city":"Ahmedabad"},{"State":"Gujarat"}]
If you need an output like this,
[{"city":"Ahmedabad","State":"Gujarat"}]
then you can implement this,
var json1 = [{"city":"Ahmedabad"}];
var json2 = [{"State":"Gujarat"}];
function jsonConcat(destinationObj, sourceObj) {
for (var key in sourceObj) {
destinationObj[key] = sourceObj[key];
}
return destinationObj;
}
//since json1 & json2 are arrays you must mention index,
//here index is 0, because it's first json object
var finalObj = jsonConcat(json1[0], json2[0])
console.log(finalObj)
IMPORTANT - This function will replace if similar keys found in both arrays !
If two json arrays have the same length, like your example, each json object is a array what includes one object.
You can loop through each item of the json arrays, then merge all of them to a object, finally push it into a array - finalObj.
My way use Object Rest/Spread Properties, the feature available with es2018:
var json1 = [{ "city": "Ahmedabad" }]
var json2 = [{ "State": "Gujarat" }]
var finalObj = [];
for (let i = 0; i < json1.length; i++) {
finalObj.push({
...json1[i],
...json2[i]
})
}
console.log(finalObj);
The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
var finalObj = json1.concat(json2)
merge your array
use reduce to merge all the items into one object
wrap in array
var combinedObj = [...json1, ...json2].reduce((acc, obj) => {
return {
...acc,
...obj
}
}, {})
var combinedArr = [...combinedObj]
You can do merge by using spread / rest operators i.e ...
var json1 = [{"city":"Ahmedabad"}]
var json2 = [{"State":"Gujarat"}]
var result = [...json1, ...json2]; //this will merge them into one.
result will be new array as we have merge them into one.
You can also user concat method of Javascript. Please refer below for concat -
https://www.w3schools.com/jsref/jsref_concat_array.asp
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_concat

NetSuite SuiteScript Join Saved Search not returning values

I have tried all manner of different ways to get this search to work properly. I even removed the filter to return values that I know the search returns. I then added the filter, and got different project ID's and verified the search (through the UI) did the job correctly.
It's a JOIN type search that should accept one parameter (project id) and return two pieces of data. That's it. Any ideas on why my parameter (filter) is not working the way it should?
var filter = new Array();
filter[0] = new nlobjSearchFilter('entityid', 'job', 'is', int_Project_ID);
var results = nlapiSearchRecord('transaction', 'customsearch_[...]', filter, null);
if ( !isNull(results) && results.length > 0 )
Here is a link to the criteria and results tabs of the search in NetSuite.
Imgur Link
try this to set the filters after loading search .
var filter = mySearch.filters;
var newfilters = [];
var filterss = {};
filterss.name = 'department';
filterss.operator = 'IS';
filterss.values = dep_fil;
filterss.join = 'employee';
filterss.summary = 'max';
newfilters.push(search.createFilter(filterss));
mySearch.filters = newfilters;
var searchResults = mySearch.run().getRange({
start : 0,
end : 500
});
you can get the values by using
searchResult.getValue({
name : 'email',
join : 'employee',
summary : 'max'
});
There are diffrent type of summary like max,sum,group etc I think the summmary is the reason.
note that this is suitescript 2 method.

Column Value in search api

I want to get the value from a Item sublist of Sales Order record.
But unable to get it. Though I can get the value of entity fields of the SO record.
Below is the snippet of the code:
var filters = new Array();
filters[0] = new nlobjSearchFilter("mainline",null,"is","T");
var column=new Array();
column[0] = new nlobjSearchColumn("trandate");
column[1] = new nlobjSearchColumn("item");
column[2] = new nlobjSearchColumn("cust_col_1");
var result = nlapiSearchRecord('salesorder', null, filters, column);
for(var i = 0; i<result.length; i++)
{
var col = result[i].getAllColumns();
var date = result[i].getFieldValue("trandate"); //I get this
var item_id = result[i].getLineItemValue("item", "item", i+1); // I don't get this
var cust_col = result[i].getLineItemValue("item", "cust_col_1", i+1); //I don't get this
}
I think I am defining the columns wrong.
This part
var item_id = result[i].getLineItemValue("item", "item", i+1); // I don't get this
var cust_col = result[i].getLineItemValue("item", "cust_col_1", i+1); //I don't get this
is also wrong, you use this syntax if you have loaded the record but for search results you just use
result[i].getValue('cust_col_1")
By specifying the filter new nlobjSearchFilter("mainline",null,"is","T"), you're basically telling the search that you don't want any line item data. This means that you will be unable to read any column data, custom or otherwise.
The mainline filter parameter has basically three options, 'F' means you want the line item details. 'T' means you just want the header data. Leaving this filter out will return one row for the header information and one row for each line item on the transaction.

How to access 'Abbreviation' field of a custom list in NetSuite custom lists

I have a custom list that is used as a matrix option of Inventory item. Its 'Color'. This custom list has an abbreviation column. I am creating a saved search on item and using Color field(join) and trying to access 'Abbreviation' field of color.
Abbreviation on custom list is available on when 'Matrix Option List' is checked.
Can someone please help me achieve this? I tried to do this through script and it seems like we cannot access 'Abbreviation' column through script. I also tried to use script to write a search directly on 'Color' - custom list and get the 'abbreviation' through search columns. It did not work. Is there a way to access 'Abbreviation' from custom lists?
Thanks in Advance
You can access it via suitescript by using the record type "customlist" and the internal id of the list like so:
var rec = nlapiLoadRecord('customlist', 5);
var abbreviation = rec.getLineItemValue('customvalue', 'abbreviation', 1);
nlapiLogExecution('DEBUG', 'abbreviation', abbreviation);
Keep in mind that the third argument of getLineItemValue is the line number, not the internal ID of the item in the list. If you want to find a specifc line item, you may want to use rec.findLineItemValue(group, fldnam, value).
Unfortunately, it doesn't look like this translates to saved searches. The suiteanswer at https://netsuite.custhelp.com/app/answers/detail/a_id/10653 has the following code:
var col = new Array();
col[0] = new nlobjSearchColumn('name');
col[1] = new nlobjSearchColumn('internalid');
var results = nlapiSearchRecord('customlist25', null, null, col);
for ( var i = 0; results != null && i < results.length; i++ )
{
var res = results[i];
var listValue = (res.getValue('name'));
var listID = (res.getValue('internalid'));
nlapiLogExecution('DEBUG', (listValue + ", " + listID));
}
However, whatever part of the application layer translates this into a query doesn't handle the abbreviation field. One thing to keep in mind is that the 'custom list' record is basically a header record, and each individual entry is it's own record that ties to it. You can see some of the underlying structure here, but the takeaway is that you'd need some way to drill-down into the list entries, and the saved search interface doesn't really support it.
I could be wrong, but I don't think there's any way to get it to execute in a saved search as-is. I thought the first part of my answer might help you find a workaround though.
Here is a NetSuite SuiteScript 2.0 search I use to find the internalId for a given abbreviation in a custom list.
/**
* look up the internal id value for an abbreviation in a custom list
* #param string custom_list_name
* #param string abbreviation
* #return int
* */
function lookupNetsuiteCustomListInternalId( custom_list_name, abbreviation ){
var internal_id = -1;
var custom_list_search = search.create({
type: custom_list_name,
columns: [ { name:'internalId' }, { name:'abbreviation' } ]
});
var filters = [];
filters.push(
search.createFilter({
name: 'formulatext',
formula: "{abbreviation}",
operator: search.Operator.IS,
values: abbreviation
})
);
custom_list_search.filters = filters;
var result_set = custom_list_search.run();
var results = result_set.getRange( { start:0, end:1 } );
for( var i in results ){
log.debug( 'found custom list record', results[i] );
internal_id = results[i].getValue( { name:'internalId' } );
}
return internal_id;
}
Currently NetSuite does not allows using join on matrix option field. But as you mentioned, you can use an extra search to get the result, you could first fetch color id from item and then use search.lookupFields as follows
search.lookupFields({ type: MATRIX_COLOR_LIST_ID, id: COLOR_ID, columns: ['abbreviation'] });
Note: Once you have internalid of the color its better to use search.lookupFields rather than creating a new search with search.create.

Get Column Values of Searched (Filtered) View Results

I am doing a search query on a viewPanel. When the results get displayed in the view, I want to loop through only the returned results and build an array of names for each row. I have the Name field in the first column of my Xpage view. I have tried the following:
var viewControl = getComponent("namesPanel");
var view = viewControl.getDataModel().getDominoViewData().getDataObject();
var entries = view.getAllEntries();
var entry = entries.getFirstEntry();
var namesArray = [];
while(entry)
{
namesArray.push(entry.getColumnValues().elementAt(0));
entry = entries.getNextEntry();
}
getComponent("DisplayNames").setValue(namesArray);
The above code returns every name in the backend Notes view regardless of my search query. I realize there is getAllEntriesByKey(), but my Xpages view is filtered by a search, not by column values.
Is there a way I can build an array of column values on only the displayed results in my view after a search? Thanks for any tips.
I think I have it figured out.
var temprows = getComponent("namesPanel");
var modelData = temprows.getDataModel();
var namesArray = [];
for(i=0; i < modelData.getRowCount(); i++)
{
modelData.setRowIndex(i);
var xspViewEntry=modelData.getRowData();
var document=xspViewEntry.getDocument();
namesArray.push(document.getItemValueString("name"));
}
getComponent("DisplayNames").setValue(namesArray);

Resources