setRedirectURLToSearchResults() 不重定向

setRedirectURLToSearchResults() not redirecting

我是 NetSuite 新手,遇到了问题。我通过用户事件脚本在表单上创建了一个按钮。 该按钮调用客户端脚本,该脚本执行保存的搜索。应该向用户显示搜索结果。

一切都在一个文件中:

function userEventBeforeLoad_AddSearchButton(type, form, request){
    if(type == 'view' || type == 'edit'){
        form.setScript('customscript_tvg_project_search_button');
        var projectid = nlapiGetFieldValue('companyname');
        form.addButton("custpage_search", "KHM Search", "performSearch('" + projectid + "')");  
    }
}

function performSearch(projectid) {
    console.log('test in client'); 
    alert('projectid = ' + projectid);

    var obj =  nlapiLoadSearch(null, 'customsearch_project_cost_detail_sublist');
    obj.setRedirectURLToSearchResults();
}

我为 userEventBeforeLoad_AddSearchButton() 创建了一个用户事件脚本记录。和 performSearch() 的客户端脚本记录。

在上面的代码中,创建了按钮并显示了警报。但是没有重定向发生。

当我查看 Firebug 中的结果时,它看起来像这样:

 {"result":"\/app\/common\/search\/searchresults.nl?api=T","id":5}

知道重定向没有发生的原因以及该怎么做吗?

编辑: 我上面的代码被精简了。我传递 projectid 的原因是我实际上需要过滤搜索结果,起诉以下两行:

var searchFilter = new nlobjSearchFilter('job', null, 'anyof', projectid);
obj.addFilter(searchFilter)

尽管 Netsuite 员工的 documentation does state that, "This method is supported in afterSubmit user event scripts, Suitelets, and client scripts", it seems from this NS User Group post 回复了与您遇到相同问题的人,但 API 实际上并未执行重定向客户端:

Redirection works on server side. Use window.location.assign(url) to navigate via script in client-side.

对此进行测试,我发现 setRedirectURLToSearchResults 确实显示正确 "load the search into the session",因此之后添加此行应该可以解决您的问题。

window.location = '/app/common/search/searchresults.nl?api=T';

setRedirectURLToSearchResults 对我也不起作用,但由于您使用的是 clientscript,您可能想试试这个:

function performSearch(projectid) {
    console.log('test in client'); 
    alert('projectid = ' + projectid);

    var searchid = 'customsearch_project_cost_detail_sublist';
    location = '/app/common/search/searchresults.nl?searchid=' + searchid;
}