This topic contains 8 replies, has 0 voices, and was last updated by leacelosacolumna 6 years, 9 months ago.
-
AuthorPosts
-
February 2, 2018 at 10:39 pm #18048
timgordonNot sure how to do this in Suitescript 2.0, can anyone post a code snippet? I have the folder id, just want to list all files in that folder. If you have a code snippet it would be much appreciated.
This is a cached copy. Click here to see the original post. -
February 3, 2018 at 5:54 pm #18049
timgordonHere is a SS1 scheduled script that does this. How do I do the same but in SS2?
Code:
function main()
{
var folderid = ‘603907’;var filters = new Array();
filters[0] = new nlobjSearchFilter(‘internalid’, null, ‘is’, folderid);var columns = new Array();
var filename = new nlobjSearchColumn(‘name’, ‘file’);
var fileid = new nlobjSearchColumn(‘internalid’, ‘file’);columns[0] = filename;
columns[1] = fileid;var searchResult = nlapiSearchRecord(‘folder’, null , filters , columns);
if(searchResult) {
for (var i = 0 ; i < searchResult.length; i++) {
thisfile = searchResult[i].getValue(filename);
thisfileid = searchResult[i].getValue(fileid);
nlapiLogExecution('DEBUG', 'Test', thisfileid + ' ' + thisfile);
}
}}
-
February 5, 2018 at 5:51 pm #18050
timgordonDoing some more research on this and it seems that in SS2 a search for documents is not possible? Can anyone confirm? The syntax should be like this and of course this works when you create a saved search in the UI.
Code:
var mySearch = search.create({
type: Search.Type.DOCUMENT,
filters : myFilters,
columns : myColumns
}); -
February 6, 2018 at 1:34 am #18051
j.ji did not understand the issue – it is possible in both SS1 and SS2, also you can search on folder object and get all files of that folder, alternatively you can search documents and set filter to parent folder.
-
February 6, 2018 at 3:02 am #18052
timgordonThanks for confirmation, I must be missing something. Can you post a code snippet of how to search documents and set filter to parent folder? This is the first thing I tried but Search.Type.DOCUMENT doesn’t seem to be a valid search type.
-
February 6, 2018 at 8:49 am #18053
JohnCColeI don’t see Document or File in the Search.Type enum in the help. Try using the string ‘file’ apposed to search.Type.Document.
-
February 7, 2018 at 4:44 am #18054
budysutjijatiHi Tim,
Just create a saved search first and make sure that in the results tab you select the columns that you need will be displayed of that particular folder. For example select the file name and file type, or anything you would like to have included. Then write down the internal id of the saved search. Now create a custom Suite Script that calls that saved search like so:
Code:
function runSearchAndFetchResult(context) {
var mySearch = search.load({
id: PLACE HERE THE INTERNAL ID OF YOUR SAVED SEARCH
});
var searchResult = mySearch.run().getRange({
start: 0,
end: 100
});
return searchResult;
}
Now all the results are stored in the searchResult object. Then you can do anything you wish with that object since the object will hold all the columns that you’ve selected earlier in the saved search. This way you can create a list of a particular folder in the file cabinet.Good luck!
-
February 8, 2018 at 4:10 pm #18055
timgordonThanks, yes that is the workaround that I used. Works fine but just feels like it should be possible to create the search in the script!
-
February 8, 2018 at 11:32 pm #18056
leacelosacolumnaIn case you’re still looking for the snippet for ad-hoc search:
Code:
require([‘N/search’], function(search) {
var documentSearch = search.create({
type: ‘file’,
‘columns’: [‘name’],
filters: [‘folder’, ‘anyof’, null, 78239]
});
var results = documentSearch.run().getRange({
start: 0,
end: 10
});
console.log(results[0].getValue(‘name’));
}); -
AuthorPosts
You must be logged in to reply to this topic.