0
votes

I have a View with a data source of the shipment table. This view has a method that contains a query. This query takes a shipment id and returns the sales id from the sales line table for this shipment. This view has a computed field that is the output of the query. The computed field is then used on a form.

If I hard code the shipment id the process works correctly. My question is how do I get the shipment id dynamically from a list of shipment ids. For instance, I have a form that lists all shipments. I want to place a field next to the shipment id that contains the calculated sales id from the process above.

Bottom line: I want the first column of a grid to be a shipment id and the second column to be the sales id for the shipment in the first column.

This is an example of the method described above that contains the query:

private static server str findSalesLine()
{
    WMSShipment     wmsShipment;
    WMSOrderTrans   wmsOrderTrans;
    SalesLine       salesLine;

    select wmsShipment
    join wmsOrderTrans
    where wmsShipment.shipmentId == '1040383'
    && wmsShipment.shipmentId == wmsOrderTrans.shipmentId
    join salesId from salesLine
    where salesLine.LineNum == wmsOrderTrans.inventTransRefLineNum
    && salesLine.SalesID == wmsOrderTrans.inventTransRefID
    && salesLine.ExternalItemId != '';

    return salesLine.SalesId;
}
2
The shipment table (WHSShipmentTable) already contains the sales id in field OrderNum (see relation SalesTable on that table). - FH-Inway
Our system has been modified. That table does not exist and that relation does not exist on our shipment table. - Count Boxer
Sorry, I was investigating in a R3 system, you are right, in R2 this table does not exist. In that case you want to transform your method to a computed column in your view (take a look at Walkthrough: Add a Computed Column to a View (AX 2012) - FH-Inway

2 Answers

0
votes

I think what you're looking for is a query range (https://msdn.microsoft.com/en-us/library/aa638454.aspx) or a display method (https://msdn.microsoft.com/en-us/library/aa595058.aspx)

Do you have any more detail or sample code?

0
votes

I would use a computed column similar to the below. I'm in a different environment than you so the SQL is not valid on my box but it should work on yours.

Add a new string computed column to your view, then set this method as the datamethod.

public static server str getSalesId()
{
    tableName       viewName = tableStr(testView);//name of your view
    DataSourceName  wmsShipmentDsName = identifierStr(WMSShipment);//change if your dsname is different on your view
    str returnStr;

    returnStr = 
    " SELECT G1.SALESID FROM SALESLINE G1 " + //don't use "T1 T2" etc as aliases on computed columns
        " JOIN WMSORDERTRANS G2 ON " +
            " G1.LINENUM = G2.INVENTTRANSREFLINENUM AND " +
            " G1.SALESID = G2.INVENTTRANSREFID AND " +
            " SALESLINE.EXTERNALITEMID <> '' " +
        " WHERE G2.SHIPMENTID == " + 
        SysComputedColumn::returnField(viewName, wmsShipmentDsName, fieldStr(WMSShipment, ShipmentId));

    return returnStr;
}