Hi,
Actually that my previous problem before but I already solved it. The relation of Return Order to Sales Order is
SalesLine.InvenrTransId == SalesLine.InventTransIdReturn
It will allow you to locate the related InvoiceId and SalesId of RMA.
Here’ s my code in x++ Hope it help.
public void processReport()
{
SalesId saledId;
Query q;
QueryRun qr;
QueryBuildDataSource qbds;
QueryBuildDataSource qbds2;
QueryBuildRange qbr;
Salestable salesTable;
SalesLine salesLine;
Salestable rmasalesTable;
SalesLine rmasalesLine;
CustInvoiceTrans custInvoiceTrans;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPersonName dirPersonName;
ReturnReasonCode returnReasonCode;
DataArea dataArea;
DirPartyPostalAddressView dirPartyPostalAddressView;
InventDim inventDim;
CustTable custTable;
;
q = this.parmQuery();
qr = new QueryRun(this.parmQuery());
while(qr.next())
{
salesLine = qr.get(tableNum(SalesLine));//Salestable from Datasource of Query
select * from salesTable
where salesLine.SalesId==salesTable.SalesId && salesLine.dataAreaId==salesTable.dataAreaId;
select * from returnReasonCode
where returnReasonCode.ReasonCodeId==salesTable.ReturnReasonCodeId&&returnReasonCode.dataAreaId==salesTable.dataAreaId;
select * from dataArea
where dataArea.id==salesLine.dataAreaId;
select * from custTable
where custTable.AccountNum==salesTable.InvoiceAccount;
select * from dirPartyPostalAddressView
where dirPartyPostalAddressView.Party == custTable.Party;
jgf_RMA_TMP.ReturnItemNum = salesTable.ReturnItemNum;
jgf_RMA_TMP.CreateDate = salesTable.createDate();
jgf_RMA_TMP.ReturnReasonCodeId = salesTable.ReturnReasonCodeId;
jgf_RMA_TMP.Description = returnReasonCode.Description;
jgf_RMA_TMP.CompanyName = dataArea.name;
jgf_RMA_TMP.Address = dirPartyPostalAddressView.Address;
jgf_RMA_TMP.Customer = salesTable.customerName();
select * from rmasalesLine
where salesLine.InventTransIdReturn == rmasalesLine.InventTransId && salesLine.dataAreaId == rmasalesLine.dataAreaId;
select * from custInvoiceTrans
where custInvoiceTrans.SalesId==rmasalesLine.SalesId&&custInvoiceTrans.dataAreaId==rmasalesLine.dataAreaId;
select * from rmasalesTable
where rmasalesLine.SalesId==rmasalesTable.SalesId && rmasalesLine.dataAreaId==rmasalesTable.dataAreaId ;
select * from hcmWorker
where rmasalesTable.WorkerSalesResponsible==hcmWorker.RecId;
select * from dirPersonName
where dirPersonName.Person == hcmWorker.Person;
select * from inventDim
where inventDim.inventDimId==rmasalesLine.inventdimid
&& inventDim.dataAreaId==rmasalesLine.dataAreaId;
jgf_RMA_TMP.InvoiceId = custInvoiceTrans.InvoiceId;
jgf_RMA_TMP.InvoiceDate = custInvoiceTrans.InvoiceDate;
jgf_RMA_TMP.Salesman = (dirPersonName.FirstName + ’ ’ + dirPersonName.MiddleName + ’ ’ + dirPersonName.LastName );
jgf_RMA_TMP.SalesID = rmasalesLine.SalesId;
jgf_RMA_TMP.DeliveryDate = rmasalesTable.DeliveryDate;
jgf_RMA_TMP.ItemId = rmasalesLine.ItemId;
jgf_RMA_TMP.Name = (rmasalesLine.Name + ’ : ’ + inventDim.InventSizeId);
jgf_RMA_TMP.QTYORDERED = rmasalesLine.QtyOrdered;
jgf_RMA_TMP.SALESUNIT = rmasalesLine.SalesUnit;
jgf_RMA_TMP.SALESPRICE = rmasalesLine.SalesPrice;
jgf_RMA_TMP.LINEAMOUNT = rmasalesLine.LineAmount;
jgf_RMA_TMP.insert();
}
}