【问题标题】:Adding a link to an invoice into a notification message将发票链接添加到通知消息中
【发布时间】:2016-10-19 03:51:55
【问题描述】:

我有一个屏幕,其中包含我想通知用户的发票。屏幕用作bodyScreenLocationEmailTemplate。到这里为止,它有效。我想为每张发票添加一个链接,以便用户可以直接从消息中打开文档。如何构建路径?这样就不行了:

此字段是在表单中创建的,该表单包含在屏幕中。此屏幕用于名为 using 的模板中 <service-call name="org.moqui.impl.EmailServices.send#EmailTemplate" async="true">


2016 年 10 月 18 日添加

我试图采纳你的建议。

<actions>
    <entity-find entity-name="mantle.account.invoice.Invoice" list="invoiceList"/>

    <script>
        import org.moqui.impl.context.WebFacadeImpl

        def httpUrl = WebFacadeImpl.getWebappRootUrl('webroot',null,false,false,ec)
    </script>
</actions>

这是日志:

21:47:18.996  WARN oquiWorker-2      o.moqui.i.c.TransactionFacadeImpl Transaction set rollback only. The rollback was originally caused by: Error rendering screen [component://HS-data/screen/Notification/PayablesDue.xml]

java.lang.NullPointerException: null 在 org.moqui.impl.context.WebFacadeImpl.makeWebappHost(WebFacadeImpl.groovy:477) ~[moqui-framework-2.0.0.jar:2.0.0] 在 org.moqui.impl.context.WebFacadeImpl.makeWebappRootUrl(WebFacadeImpl.groovy:520) ~[moqui-framework-2.0.0.jar:2.0.0] 在 org.moqui.impl.context.WebFacadeImpl.getWebappRootUrl(WebFacadeImpl.groovy:467) ~[moqui-framework-2.0.0.jar:2.0.0] 在 org.moqui.impl.context.WebFacadeImpl$getWebappRootUrl.call(Unknown Source) ~[?:?] 在 org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-2.4.7.jar:2.4.7] 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-2.4.7.jar:2.4.7] 在 PayablesDue_xml_screen_actions.run(PayablesDue_xml_screen_actions:11) ~[script:?]

【问题讨论】:

    标签: html moqui


    【解决方案1】:

    您正在寻找的是 WebFacade.getWebappRootUrl() 方法。在您的模板中使用类似这样的调用来获取基本 URL:

    ec.web.getWebappRootUrl(true, null)
    

    当没有 WebFacade 时,例如在异步服务中运行时,您将不得不降低一个级别,并且 WebFacadeImpl 中有一个静态方法(当您没有时不那么方便)要通过的标准接口),这是方法签名:

    String getWebappRootUrl(String webappName, String servletContextPath, boolean requireFullUrl, Boolean useEncryption, ExecutionContextImpl eci)
    

    标准的 webappName 是“webroot”,除非你在你的 Moqui Conf XML 文件中做一些花哨的事情,否则它可以是一个静态字符串。如果您的 Moqui webapp 安装在根目录上,则 servletContextPath 可以为 null 或空字符串(通常是这种情况;如果没有请求,我们可以访问 ServletContext 以查看其安装位置,这无法自动确定)。

    【讨论】:

    • 我在原始消息中添加了评论。
    • 我看到了其中的 NPE 及其原因,更改了一些代码(提交 #3cb17b5),以便更好地处理空 webFacade 和请求。请注意,对于没有可用请求的正确 URL,您不能使用虚拟主机,必须在 Moqui Conf XML 中的 webapp 元素上设置 http-host、https-host 等。
    猜你喜欢
    • 2018-08-22
    • 2021-03-06
    • 2010-10-23
    • 1970-01-01
    • 2022-01-22
    • 2023-03-20
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多