Adding a field only to some lines of an order

Hi everyone,
I have this issue that is blocking me. I have created a report with Docentric, I created a list where I put the lines (SalesLine) associated to my Packing Slip Journal. So if I will print the number of lines associated to each order I’m going to print. Each line has a field called Configuration, but for some of them the field is empty. For example if I try to print an order with 3 lines, with only the first one having the configuration, what I expect from my Report is to Print the configuration for the first line and not for the other too, but that’s not happening. Anyone has any suggestion to give me? I’ve been not to use a node child, but I have never done anything like that.



this is my code: `else if (_rdpTableName == tableStr(SalesPackingSlipDetailsTmp))
{
CustPackingSlipJour custPackingSlipJour = this.custPackingSlipJour();
//DocXmlRecord jourDataRecord = _addingRecord.addChildRecord(custPackingSlipJour);
SalesLine salesLine;
SalesTable salesTableHeader;

        InventDim inventDim;
        while select salesLine
where salesLine.SalesId == salesTableHeader.SalesId
        {
            // Per ogni riga, ottieni la configurazione se presente
            select firstonly configId from inventDim
            where inventDim.inventDimId == salesLine.InventDimId ;

            _addingRecord.addCalculatedField('Configurazione', inventDim.configId);
        }`

Hi @Fabfab97,

It’s hard to determine the issue from the code provided. The best approach would be to debug it, especially to verify if your conditional statement is being executed correctly and if the SQL query (
select firstonly configId from inventDim where inventDim.inventDimId == salesLine.InventDimId
) is returning the expected results.

the result expected from the query is correct, cause if I get the Configuration field correctly. The problem is when I have multiple lines in my SalesLine, and i need to print the right configuration in its line. If I put the _addingRecord method inside the while select loop, once I try to print I get the error “Configuration field already added to the report” (because I think it tries to add a new Configuration field for each line, so at the secondo line the field is already there), and If I put it outside the loop, of course it takes only the last result of the loop and put it in every configuration field, so if the last one is empty, every configurations will result empty. I wanted to ask if there is a standard approach to this, on inserting fields on Saleslines. Since I’m writing my code inside and extension class, in the original class I found this tip :` else if (_rdpTableName == tableStr(SalesPackingSlipDetailsTmp))
{
super(_addingRecord, _rdpTableRecord, _rdpTableName);

        // TODO: Add here additional fields from the related CustPackingSlipTrans table (or some other tables).
        //SalesPackingSlipDetailsTmp salesPackingSlipDetailsTmp = _rdpTableRecord;
        //CustPackingSlipTrans custPackingSlipTrans = this.custPackingSlipTrans(salesPackingSlipDetailsTmp.CustPackingSlipTrans);
        //_addingRecord.addCalculatedField('LineNum', custPackingSlipTrans.LineNum);
    }`

But I can’t fiure out how to do it

Hello @Fabfab97 and welcome to the forum!

Usually for technical support you’d have to contact the Docentric support (support@docentric.com), but I would like to help you figure this out, as it will also help others in the future.

I think the only problem here is that you’re using while select in the outer loop, just a normal select will do fine, since the outer method is already looping through the records.

The following code should be all that is needed to add the configId to your DDSP:

else if (_rdpTableName == tableStr(SalesPackingSlipDetailsTmp))
        {
            super(_addingRecord, _rdpTableRecord, _rdpTableName);

            SalesPackingSlipDetailsTmp salesPackingSlipDetailsTmp = _rdpTableRecord;
            CustPackingSlipTrans custPackingSlipTrans = this.custPackingSlipTrans(salesPackingSlipDetailsTmp.CustPackingSlipTrans);
            InventDim inventDim;
            
            select firstonly configId from inventDim
                where inventDim.inventDimId == custPackingSlipTrans.InventDimId;

            _addingRecord.addCalculatedField('Configurazione', inventDim.configId);
        }

Thank you very much, now it works just fine!