使用SuiteScript填充转储单

时间:2018-05-07 15:22:06

标签: netsuite populate suitescript

目前的问题是我无法提交订单项。我是否需要添加更多字段,即使项目是唯一需要的项目?

function OLDcreateTO() //(request, response)
{
    for ( var i = 1; i < lines + 1 ; i++ )
    {
        nlapiLogExecution('DEBUG','<Before Load Script> type: '+type,"line # " + i);
        arrayName[i] = PORecord.getLineItemValue('item', 'item', i ); 
        nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, arrayName[i]);
    }

    nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, lines + ' lines');


    var TOrecord = nlapiCreateRecord ('transferorder');
    var TOrecordID = TOrecord.getId();
    TOrecord.setFieldValue('customform',128);
    //subsidiaries CC bedford id is 2
    TOrecord.setFieldValue('subsidiary',2);
    //testing for location and transfer location, 144 & 145
    TOrecord.setFieldValue('location',144);
    TOrecord.setFieldValue('transferlocation',145);

    nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'break 4');
    // add new lines to a sublist
    nlapiSelectNewLineItem('item');
    // set the item and location values on the currently selected line
    nlapiSetCurrentLineItemValue('item', 'item', arrayName[1]);
    nlapiSetCurrentLineItemValue('item', 'location', 6);
    // commit the line to the database
    nlapiCommitLineItem('item');
    nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'break 5');

    var TOResult = nlapiSubmitRecord(TOrecord, true, true);
    var TOTranID= nlapiLookupField('transferorder', TOResult, 'tranid');
     nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'break 6');
    var poURL = nlapiResolveURL('RECORD', 'transferorder', TOResult);

    nlapiSetRedirectURL('RECORD','transferorder', TOResult);


     }

因此,我试图让采购订单的项目通过采购订单上的按钮填充新转储单上的项目字段。在此之前,用户可以在提交记录并创建TO之前对记录进行任何更改。主要问题是我不知道如何从脚本中填充空白TO。我通过url字符串重定向它,但我确信有更好的方法可以做到。

总结。

- 用户点击&#34;创建TO&#34; PO上的按钮

- 将用户带到&#34;创建TO&#34;所有项目(以及一些不同的信息)根据PO预先填充的页面。

-User编辑记录然后提交。

suitescript 1.0     // create_to_button

var newId ;
var newType ;
function beforeload(type)
{
    if(nlapiGetContext().getRole() == '3')
    {
        if(type =='view' || type == 'edit')
        {
            newId = nlapiGetRecordId();
            newType = nlapiGetRecordType();

                if(newType == 'purchaseorder')
                {

                    var strURL = "https://system.na2.netsuite.com/app/accounting/transactions/trnfrord.nl"
                    var scriptbutton = 'window.open(' + String.fromCharCode(39) + strURL + String.fromCharCode(39) + ')' ;
                    //nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'URL: '+strURL + '&id=' + newId);
                    form.addButton('custpage_createpo', 'Create TO', scriptbutton);

                }

        }
    }
}

function loadTO() //(request, response)
{
    nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'hello');
     nlapiLoadRecord(newType, newId);
}

任何想法或建议表示赞赏。 布兰登

1 个答案:

答案 0 :(得分:0)

如果您知道TO将被保存,您将打开一个将填充TO的Suitelet。使用带有来自nlapiResolveURL的url的nlapiSetRedirect保存并重定向到新的TO。

如果可能未保存TO,则将一些参数添加到您正在使用的tasklink URL中,并将填充逻辑添加到TO的客户端init函数中。您可能需要使用beforeLoad用户事件脚本向TO添加一些自定义字段,以提供客户端脚本所需的信息。 (您的客户端脚本也可以查看查询字符串参数,但根据您正在执行的操作,服务器端查找可能会更快)。