0

I have a simple RDP report, works fine and as expected. When run in selected legal entity.

enter image description here

I want to enable cross company reporting so that when in selected company I can see data from all other companies if required. I enable property in AOT query and rebuild which adds company range in report query. I am still in same legal entity.

enter image description here

I select same company as legal entity I am in.

enter image description here

All other ranges etc. are correct, data is now incorrect. What else do I have to do to get this working? This is a simple RDP report code pasted below. I have tried enabling crosscompany on queryrun object but is still not working. I just get loads of 0's everywhere.

enter image description here

What else do I need to do to get this working correctly? The ranges code can be ignored this simply captures ranges user selects and prints on report.

[   
SRSReportQueryAttribute(queryStr(WIP))
]
public class WIP extends SRSReportDataProviderBase
{
    tmpWIP tmpWIP;
    TmpRanges tmpRanges;

    [
        SRSReportDataSetAttribute('tmpWIP')
    ]
        public tmpWIP gettmpWIP()
    {
        select tmpWIP;
        return tmpWIP;
    }

    [
        SRSReportDataSetAttribute(tablestr(TmpRanges))
    ]
    public TmpRanges getTmpRanges()
    {
        select tmpRanges;
        return tmpRanges;
    }

public void processReport()
    {
        ProjTable                       projTable;
        ProjTransPosting                projTransPosting;
        CostControlTransCommittedCost   costControlTransCommittedCost;
        EstimateTemplatePeriod      EstimateTemplatePeriod;
        QueryRun                        queryRun;

    // Get the query from the runtime using a dynamic query.
    queryRun = new QueryRun(this.parmQuery());
    queryRun.allowCrossCompany(true);

    while (queryRun.next())
    {
        projTable = queryRun.get(tablenum(ProjTable));
        ProjTransPosting = queryRun.get(tablenum(ProjTransPosting));
        CostControlTransCommittedCost = queryRun.get(tableNum(CostControlTransCommittedCost));
        EstimateTemplatePeriod = queryRun.get(tableNum(EstimateTemplatePeriod));

        tmpWIP.clear();
        tmpWIP.CustAccount = projTable.CustAccount;
        tmpWIP.ProjId = projTable.ProjId;
        tmpWIP.Name = projTable.Name;
        tmpWIP.CustName = projTable.custName();
        tmpWIP.AmountMst = projTransPosting.AmountMst;
        tmpWIP.CostAmount = projTransPosting.costAmount();
        tmpWIP.ProjTransType = projTransPosting.ProjTransType;
        tmpWIP.CategoryId = projTransPosting.CategoryId;
        tmpWIP.CommittedCostAmount = costControlTransCommittedCost.AmountMst;
        tmpWIP.EstimateValue = EstimateTemplatePeriod.Value;
        tmpWIP.PostingType = projTransPosting.PostingType;
        tmpWIP.insert();
    }
    this.rangesToTable(this.parmQuery());
}

public void rangesToTable(Query _query)
{
    QueryBuildDataSource    qbds;
    QueryBuildRange         queryBuildRange;
    LabelType               tableLabel;
    int                     occurrence;
    int                     dataSourceNo;
    int                     i;

    for (dataSourceNo = 1; dataSourceNo <= _query.dataSourceCount(); dataSourceNo++)
    {
        qbds = _query.dataSourceNo(dataSourceNo);
        if (qbds.enabled())
        {
            occurrence = SysQuery::tableOccurrence(_query, qbds.table(), dataSourceNo);
            tableLabel = tableId2pname(qbds.table()) + SysQuery::tableOccurrenceText(occurrence);

            for (i = 1; i <= qbds.rangeCount(); i++)
            {
                queryBuildRange = qbds.range(i);

                if (queryBuildRange.value() && queryBuildRange.status() != RangeStatus::Hidden)
                {
                    tmpRanges.clear();
                    tmpRanges.FieldLabel   = fieldId2pname(qbds.table(), queryBuildRange.field());
                    tmpRanges.RangeValue   = queryBuildRange.value();
                    tmpRanges.insert();
                }
            }
        }
    }
}
}
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
jhowe
  • 10,198
  • 19
  • 48
  • 66
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jan 12 '18 at 11:27
  • Have you tried examining the query? i.e. `info(queryRun.toString())`? – Alex Kwitny Jan 12 '18 at 16:29
  • I have tried using this but only query object seems to give string not queryrun, not sure how to add query object into this I’m fairly new to x++ development. Thanks! – jhowe Jan 15 '18 at 18:04

2 Answers2

1

The allowCrossCompany method give you the right to query in more than one company, but the query does not know in which companies to do so. You do this by calling addCompanyRange for each applicable company.

In a MorphX report the documented approach amounts to:

public void init()
{
    super();
    this.query().allowCrossCompany( true );
    this.query().addCompanyRange( "dat" );
    this.query().addCompanyRange( "dmo" );
}

Similar for other uses of cross company queries, you have to tell which companies it applies.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • Hi thanks for your fast response it is much appreciated. Sorry I’m away at the moment so haven’t been able to look at this properly, I do not understand what you’re saying, the query should know what company I’m looking at as I’m picking it in the company range? This gets enabled as soon as allowcrosscompany is set to yes as shown in the screenshots. – jhowe Jan 15 '18 at 18:02
  • In that case you should verify that the query is updated correctly. – Jan B. Kjeldsen Jan 15 '18 at 18:06
  • Ok how would I modify my code to expose SQL query and I will check it... thanks. – jhowe Jan 17 '18 at 10:29
0

I have found that this is down to fetch mode of 1:N not supporting property 'allow cross company in AOT'. I am currently rebuilding this query in X++ to workaround the issue.

jhowe
  • 10,198
  • 19
  • 48
  • 66