获取特定Netsuite文件夹中的文件列表

时间:2019-04-19 15:35:23

标签: c# netsuite

我正在尝试检索文件柜中特定文件夹中的文件列表。执行搜索时,将获得指定文件夹中的所有文件以及该文件夹下的所有文件夹。我尝试过使用FileSearchBasicFileSearchAdvanced,两者都给我相同的结果。

是否可以只获取指定文件夹ID中的文件?

var search = new FileSearchBasic
{
    folder = new SearchMultiSelectField
    {
        @operator = SearchMultiSelectFieldOperator.anyOf,
        @operatorSpecified = true,
        searchValue = new[] { new RecordRef
        {
            internalId = "1234"
        }}
    }
};

var result = ns.search(search);
if (result.status.isSuccess)
{
    foreach (var record in result.recordList)
    {
        if (record is File file)
        {
            Console.WriteLine($"{file.folder.internalId} - {file.name}");
        }
    }
}

此代码将显示以下列表,其中文件夹1236是文件夹1234的子文件夹

1234 - lodash.js
1234 - dt.timer.js
1234 - dt.search.js
1234 - dt.customer.js
1234 - dt.safeExecute.js
1236 - processRawLocationData.js

1 个答案:

答案 0 :(得分:1)

通过执行FolderSearchAdvanced()并使用文件联接而不是FileSearchAdvanced(),我只能获得指定文件夹中的文件。之所以这样说是有道理的,因为您也必须在SuiteScript中也这样做。

仍然可以接受其他方法。

var search = new FolderSearchAdvanced()
{
    criteria = new FolderSearch()
    {
        basic = new FolderSearchBasic()
        {
            internalId = new SearchMultiSelectField()
            {
                @operator = SearchMultiSelectFieldOperator.anyOf,
                searchValue = new[] { searchValue },
                operatorSpecified = true
            },
        }
    },
    columns = new FolderSearchRow
    {
        basic = new FolderSearchRowBasic()
        {
            internalId = new[] { new SearchColumnSelectField() },
            name = new [] { new SearchColumnStringField() }
        },
        fileJoin = new FileSearchRowBasic()
        {
            internalId = new[] { new SearchColumnSelectField() },
            name = new[] { new SearchColumnStringField() },
            modified = new[] { new SearchColumnDateField() },
            documentSize = new[] { new SearchColumnLongField() }
        }
    }
};

var results = ns.search(search);
if (results.status.isSuccess)
{
    foreach (var result in results.searchRowList)
    {
        if (result is FolderSearchRow row)
        {
            var fileId = row.fileJoin.internalId[0].searchValue.internalId;
            var fileName = row.fileJoin.name[0].searchValue;

            Console.WriteLine($"{fileId} - {fileName}");
        }
    }
}