首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >触发客户端脚本并在保存时重定向回Suitelet

触发客户端脚本并在保存时重定向回Suitelet
EN

Stack Overflow用户
提问于 2022-01-19 09:47:57
回答 1查看 1.9K关注 0票数 0

编辑1:已编辑代码客户端以包括解决url建议

这是来自触发客户端脚本的按钮点击一个Suitelet?的后续报道

这个问题已经得到了回答,现在我被脚本的另一个部分卡住了。我也在Netsuite社区上发布了这篇文章,尽管我在那里收到的回复让我更加困惑。

如果我的StackOverflow发帖礼仪/规则在后续张贴或交叉张贴方面有错误,请提前道歉。

场景:有一个带有按钮的Suitelet,它会导致在编辑模式下加载自定义记录页面。字段值是使用客户端脚本在定制记录上设置的,该脚本是在单击手提包上的按钮时触发的。

自定义记录

一切都按预期进行,直到到达客户端脚本的函数saveRecord部分。

在保存记录后,我试图让页面重定向回行李箱,尽管无法让它工作。

到目前为止,我已经尝试将N/重定向模块添加到客户端脚本中,并使用以下方法:

代码语言:javascript
复制
    function saveRecord(context) {
        redirect.redirect({
        url: '/app/site/hosting/scriptlet.nl?script=313&deploy=1',
       
    });
    
        return true;
      }

手提箱没有登录即可使用。

我也试过

代码语言:javascript
复制
     function saveRecord(context) {
        window.open(
          "https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=f"
        );
    
        return true;
      }

唱片肯定是保存下来的,尽管它并没有重定向回苏特莱特。

编辑这是完全有效的Suitelet脚本:

代码语言:javascript
复制
/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(["N/ui/serverWidget", "N/search"], function (ui, search) {
    function getCiSetup() {
        var customrecord_nsts_ci_setupSearchObj = search.create({
            type: "customrecord_nsts_ci_setup",
            filters: [],
            columns: [
                search.createColumn({
                    name: "custrecord_nsts_ci_admin_email",
                    label: "Administrator Emails",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_search_dtl",
                    label: "Invoice Details Saved Search",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_search",
                    label: "Invoice Summary Saved Search",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_type",
                    label: "Invoice Type",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_layout",
                    label: "Default CI Layout",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_duedate",
                    label: "Due Date",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_email_sender",
                    label: "Email Sender",
                }),
                search.createColumn({
                    name: "custrecord_nsts_ci_email_template",
                    label: "Email Template",
                }),
            ],
        })

        return customrecord_nsts_ci_setupSearchObj
    }

    var exports = {}

    function onRequest(context) {
        if (context.request.method === "GET") {
            var form = ui.createForm({
                title: "Consolidated Invoicing Type",
            })
            // form.clientScriptModulePath =
            //   "SuiteScripts/sdf_ignore/Consolidated Invoice Client Script.js";
            form.clientScriptFileId = 8378

            form.addButton({
                id: "recurring",
                label: "Recurring",
                functionName: "executeRecurring",
            })

            form.addButton({
                id: "other",
                label: "Other",
                functionName: "executeOther",
            })

            var sublist = form.addSublist({
                id: "custpage_ci_setup",
                type: ui.SublistType.LIST,
                label: "Consolidated Invoice Set Up",
            })

            sublist.addField({
                id: "custpage_invoice_dtl",
                label: "Invoice Details",
                type: ui.FieldType.TEXT,
            })

            sublist.addField({
                id: "custpage_invoice_summry",
                label: "Invoice Summary",
                type: ui.FieldType.TEXT,
            })
            var htmlBody = ""
            htmlBody += "<html>"
            htmlBody += "<head>"
            htmlBody += "</head>"
            htmlBody += "<body>"

            htmlBody += ""

            htmlBody += "</body></html>"

            form.addField({
                id: "custpage_html",
                label: "html",
                type: ui.FieldType.INLINEHTML,
            }).defaultValue = htmlBody
            var ciSetup = getCiSetup()
            var i = 0

            ciSetup.run().each(function (result) {
                log.debug("result", result)
                var invoiceSummary = result.getText("custrecord_nsts_ci_search")
                var invoiceDetail = result.getText("custrecord_nsts_ci_search_dtl")
                sublist.setSublistValue({
                    id: "custpage_invoice_dtl",
                    line: i,
                    value: invoiceDetail,
                })
                sublist.setSublistValue({
                    id: "custpage_invoice_summry",
                    line: i,
                    value: invoiceSummary,
                })
                i++
                return true
            })

            context.response.writePage(form)
        } else if ((context.response.method = "POST")) {
            log.debug({
                title: "request method type",
                details: "suitelet is posting",
            })
        }
    }
    exports.onRequest = onRequest
    return exports
})

这是完整的客户端脚本,与上面的Suitelet一起工作

代码语言:javascript
复制
/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(["N/record", "N/runtime", "N/url", "N/log"], function (
  record,

  runtime,
  url,
  log
) {
  /**
   * @param {ClientScriptContext.pageInit} context
   */

  function pageInit(context) {}

  function executeRecurring(context) {
    var scriptObj = runtime.getCurrentScript();
    var recordType = scriptObj.getParameter("custscript_ci_suitelet_record");
    //page url is for the link to the CI invoice set up page when it is in edit mode. There is only one record that can be saved for this record type
    var pageUrl =
      "https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=436&id=1&e=T";

    var url = new URL(pageUrl);
    //Add additional code
    window.location.href = url;

    var objRecord = record.load({
      type: "customrecord_nsts_ci_setup",
      id: 1,
      isDynamic: true,
    });
    //INVOICE SUMMARY SAVED SEARCH *
    objRecord.setValue({
      fieldId: "custrecord_nsts_ci_search",
      value: 2079,
    });
    //INVOICE DETAILS SAVED SEARCH
    objRecord.setValue({
      fieldId: "custrecord_nsts_ci_search_dtl",
      value: 2078,
    });
    //DEFAULT CI LAYOUT *
    objRecord.setValue({
      fieldId: "custrecord_nsts_ci_layout",
      value: 1,
    });

    objRecord.save({
      enableSourcing: true,
      ignoreMandatoryFields: false,
    });

    // window.open(redirectUrl);
    // window.location.assign(
    //   "https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=f"
    // );
    //the window location is redirecting back to the suitelet screen
    window.location.assign(
      "https://tstdrv.app.netsuite.com/app/site/hosting/scriptlet.nl?script=1123&deploy=1&compid=TSTDRV&whence="
    );

    //look into window.close for the newly opened window
  }
  //this is reiterating the parameters for the saved searches that was entered above
  var customSubmit = function returnFields(context) {
    record.submitFields.promise({
      type: "customrecord_nsts_ci_setup",
      id: 1,
      values: {
        custrecord_nsts_ci_layout: 1,
        custrecord_nsts_ci_search_dtl: 2078,
        custrecord_nsts_ci_search: 2079,
      },
    });
  };
  // window.onbeforeunload = null;

  // var suiteletURL = url.resolveScript({
  //   scriptId: "customscript_ci_suitelet",
  //   deploymentId: "customdeploy_ci_suitelet",
  // });

  // window.open(suiteletURL, "_self", false);
  // };

  // function saveRecord(context) {
  //   window.open(
  //     "https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=f"
  //   );

  function executeOther(context) {
    var scriptObj = runtime.getCurrentScript();
    var recordType = scriptObj.getParameter("custscript_ci_suitelet_record");
    //on the  record for the client script, there is a parameter for    List/Record pointing to record type: CI - Setup
    //the client script is deployed against the suitelet record
    //on the deployment record, there is a parameter pointing to record ID 1 which is the only set up record that can exist since there cannot be more than one set up record

    //edit mode for the CI invoice set up page record
    var pageUrl =
      "https://tstdrv0.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=436&id=1&e=T";

    var url = new URL(pageUrl);
    //Add additional code
    window.location.href = url;

    var objRecord = record.load({
      type: "customrecord_nsts_ci_setup",
      id: 1,
      isDynamic: true,
    });
    //INVOICE SUMMARY SAVED SEARCH *
    objRecord.setValue({
      fieldId: "custrecord_nsts_ci_search",
      value: 1669,
    });
    //INVOICE DETAILS SAVED SEARCH
    objRecord.setValue({
      fieldId: "custrecord_nsts_ci_search_dtl",
      value: 1668,
    });
    //DEFAULT CI LAYOUT *
    objRecord.setValue({
      fieldId: "custrecord_nsts_ci_layout",
      value: 1,
    });

    objRecord.save({
      enableSourcing: true,
      ignoreMandatoryFields: false,
    });

    // window.open(redirectUrl);
    // window.location.assign(
    //   "https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=f"
    // );

    window.location.assign(
      "https://tstdrv.app.netsuite.com/app/site/hosting/scriptlet.nl?script=1123&deploy=1&compid=TSTDRV&whence="
    );

    //look into window.close for the newly opened window
  }

  var customSubmit = function returnFields(context) {
    record.submitFields.promise({
      type: "customrecord_nsts_ci_setup",
      id: 1,
      values: {
        custrecord_nsts_ci_layout: 1,
        custrecord_nsts_ci_search_dtl: 1669,
        custrecord_nsts_ci_search: 1668,
      },
    });
  };
  // window.onbeforeunload = null;

  // var suiteletURL = url.resolveScript({
  //   scriptId: "customscript_ci_suitelet",
  //   deploymentId: "customdeploy_ci_suitelet",
  // });

  // window.open(suiteletURL, "_self", false);
  // };

  // function saveRecord(context) {
  //   window.open(
  //     "https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=f"
  //   );

  return {
    pageInit: pageInit,
    executeRecurring: executeRecurring,
    executeOther: executeOther,
    customSubmit: customSubmit,

    // saveRecord: saveRecord,
  };
});

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70768385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档