我已经为APReleaseCheckProcess创建了扩展。我需要发送文档的RefNbr,其中DocType ='REF'(发送供应商退款的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编写代码以生成上述查询。
答案 0 :(得分:1)
假设您要为登录用户的公司运行查询,而不会进行错误检查:
((APInvoice)PXSelect<APInvoice, Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>>>.Select(sender.Graph, refNbr)).InvoiceNbr
如果您需要为登录用户公司以外的公司运行查询,建议的方法是将数据放在没有CompanyID字段的表中。
BQL强烈执行公司的隔离,除非您已登录此公司,否则您将无法从其他公司检索数据。如果此数据与其他公司分开/共享,ORM还会负责从其他公司ID返回数据。对于不包含CompanyID字段的表,系统将返回此表中包含的所有数据。