【问题标题】:retrieve data using BQL in Acumatica在 Acumatica 中使用 BQL 检索数据
【发布时间】:2017-04-17 09:30:03
【问题描述】:

我已经为 APReleaseCheckProcess 创建了扩展。我需要将 DocType = 'REF' 的文档的 RefNbr(发送供应商退款的 RefNbr)发送到另一个数据库。 我在下面使用了这段代码。

public static class APReleaseCheckProcess
  {
      public static void APPaymentRowPersisted(PXCache sender, PXRowPersistedEventArgs e)
      {
          string serverJade, dbJade, userJade, passJade;

          serverJade = "BS-DEV64\\SQL2014"; //--- Server Jade : 192.168.10.13
          dbJade = "SGL"; //--- DB Jade Live : SGL || DB Jade test : SGL_TEST
          userJade = "sa"; //--- User ID : sa
          passJade = "Admin1"; //--- Password : sa_091073

          if (e.TranStatus == PXTranStatus.Completed && e.Operation == PXDBOperation.Update)
          {
              var doc = e.Row as APPayment;
              #region Doc Type = Vendor Refund
              if (doc != null && doc.Released == true && doc.DocType == "REF")
              {
                  foreach (APAdjust oldadj in PXSelect<APAdjust,
                      Where<
                          APAdjust.adjgDocType, Equal<Required<APPayment.docType>>,
                              And<APAdjust.adjgRefNbr, Equal<Required<APPayment.refNbr>>,
                              And<APAdjust.adjNbr, Less<Required<APPayment.lineCntr>>>>>>
                      .Select(sender.Graph, doc.DocType, doc.RefNbr, doc.LineCntr))
                  {
                      string refNbr = oldadj.AdjdRefNbr;
                      string docType = oldadj.AdjdDocType;

                      // I need to retrieve InvoiceNbr from this query below using BQL statement:
                      string InvNbr = "select InvoiceNbr from APInvoice where CompanyID = 2 and RefNbr = refnbr";

                      // query to send to another database
                      using (SqlConnection conJade = new SqlConnection("server = " + serverJade + "; database = " + dbJade + "; user = " + userJade + "; password = " + passJade + ""))
                                  {
                                      string qRefund = "update b set b.cano = "+doc.RefNbr+"" +
                                                       "from evmaster as b " +
                                                            "inner join evmaster as a on a.svno = b.vchno " +
                                                       "where a.vchno = "+InvNbr+"";
                                      conJade.Open();
                                      using (SqlCommand comJade = new SqlCommand(qRefund, conJade))
                                      {
                                          SqlDataReader sdr = comJade.ExecuteReader();
                                          sdr.Close();
                                      }
                                  }
                  }
              }
              #endregion
          }
      }
  }

如何编写代码以在 Acumatica Customize 项目中使用 BQL 生成上述查询。

【问题讨论】:

  • 您是否查看过 Acumatica 大学的 API 参考和培训材料?
  • 感谢您的建议,我会检查一下。其实下面的答案一直有效,我会使用它。但我想如果我有其他关于 BQL 的案例,我肯定会查看培训材料。

标签: c# customization acumatica


【解决方案1】:

假设您想为登录用户的公司运行查询,而不进行错误检查:

((APInvoice)PXSelect<APInvoice, Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>>>.Select(sender.Graph, refNbr)).InvoiceNbr

如果您需要对登录用户所在公司以外的公司进行查询,推荐的方法是将数据放在没有 CompanyID 字段的表中。

BQL 严格执行公司隔离,除非您登录到该公司,否则您将无法从其他公司检索数据。如果这些数据与另一家公司拆分/共享,ORM 还负责返回来自其他公司 ID 的数据。对于不包含 CompanyID 字段的表,系统会返回该表中包含的所有数据。

【讨论】:

  • 我需要为当前公司运行查询,当然它与登录用户相同。我已经尝试过你的 BQL 并且它有效。谢谢你的回答:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-11
  • 1970-01-01
  • 2022-12-15
  • 2021-08-12
  • 1970-01-01
  • 2016-10-30
  • 1970-01-01
相关资源
最近更新 更多