2017-06-23 44 views
0

我有一个工作流程,添加一个按钮“打开链接”,并在名为“URL”的记录中包含超链接到NetSuite附件的一个字段。我想添加一个工作流程操作脚本,在另一个页面中打开此URL。我已将脚本和工作流程操作添加到工作流程中。我的脚本:NetSuite/Suitescript /工作流程:点击按钮后,如何从字段中打开URL?

function openURL() { 

var url = nlapiGetFieldValue('custbody_url'); 

window.open(url);  

} 

我得到这个脚本错误点击按钮后:“类型错误:无法找到函数对象的翻译:开放

我怎样才能改变我的脚本,以便它打开的URL。现场?

(当我尝试在控制台此功能)

谢谢!

回答

1

你想在查看或编辑记录时使用它吗?他们有略微不同的脚本。我会假设你想让按钮在查看记录时工作,但是我会写它,因此即使在编辑文档时也能正常工作。

有关Netsuite设置方式的难点在于它需要两个脚本,一个用户事件脚本和一个客户端脚本。 @michoel建议的方式也可能起作用......但我从未在个人面前通过文本插入脚本。 今天的某个时候我可能会尝试。

下面是您可以使用的用户事件(尽管我自己还没有对其进行测试,所以您应该在将其部署到每个人之前通过测试运行它)。

function userEvent_beforeLoad(type, form, request) 
{ 
    /* 
    Add the specified client script to the document that is being shown 
    It looks it up by id, so you'll want to make sure the id is correct 
    */ 
    form.setScript("customscript_my_client_script"); 

    */ 
    Add a button to the page which calls the openURL() method from a client script 
    */ 
    form.addButton("custpage_open_url", "Open URL", "openURL()");  
} 

将此作为用户事件脚本的套件文件使用。将脚本页面中的加载前功能设置为userEvent_beforeLoad。确保将其部署到您希望运行的记录中。

这是客户端脚本。

function openURL() 
{ 
    /* 
    nlapiGetFieldValue() gets the url client side in a changeable field, which nlapiLookupField (which looks it up server side) can't do 
    if your url is hidden/unchanging or you only care about view mode, you can just get rid of the below and use nlapiLookupField() instead 
    */ 
    var url = nlapiGetFieldValue('custbody_url'); 

    /* 
    nlapiGetFieldValue() doesn't work in view mode (it returns null), so we need to use nlapiLookupField() instead 
    if you only care about edit mode, you don't need to use nlapiLookupField so you can ignore this 
    */ 
    if(url == null) 
    { 
     var myType = nlapiGetRecordType(); 
     var myId = nlapiGetRecordId(); 
     url = nlapiLookupField(myType, myId,'custbody_url'); 
    } 

    //opening up the url 
    window.open(url);  
} 

将其作为客户端脚本添加,但不进行任何部署(用户事件脚本会将它附加到表单中)。确保这个脚本的ID为customscript_my_client_script(或者你在form.setScript()中用户事件脚本中使用的任何脚本ID),否则这将不起作用。

要记住的另一件事是,每个记录只能使用form.setScript()(我认为?)附加到一个脚本,所以你可能想标题的用户事件脚本和客户端脚本的东西有关的你正在部署它的形式。使用form.setScript等同于在“自定义表单”菜单中时设置脚本值。

如果你能得到@ michoel的答案,那最终可能会更好,因为你将逻辑全部保存在一个脚本中(从我的角度来看)可以更容易地管理你的脚本。

0

你碰到的问题是工作流程的Actio n脚本在服务器端执行,因此您无法执行客户端操作,如打开新选项卡。我建议使用用户事件脚本,它可以将客户端代码“注入”按钮的onclick函数。

function beforeLoad(type, form) { 
    var script = "window.open(nlapiGetFieldValue('custbody_url'))"; 
    form.addButton('custpage_custom_button', 'Open URL', script); 
} 
+0

这为我打开了一个空白页面。即使我尝试添加: 'var rec = nlapiLoadRecord('vendorbill',nlapiGetRecordId()); var url = rec.getFieldValue('custbody_url');' 并尝试打开此页面,它不会执行任何操作并停留在页面上 – bluejay92

相关问题