selecting one record from form to report.

Hi,

I have Logistics table and form. and i have report, it takes project id from table, and automaticaly it is selected in report dialog, But i need to put this report in another form. And what is wrong, that in Logistics form it is working ok, but in other form not. Then i select record, report dialog always shows the same project ID(first one). I need that it repair it but i do not know how. Report and form was made not by be.

Thanks.

Basically you need the selected record range Project Id to be captured in the report dialog?

Here is how I have developed this, for a similar report - in Logistics module…

First you need to get a tidy Dialog;

public Object dialog(Object _dialog)
{
Dialog dialog;
;

dialog = super(_dialog);

dialog.caption(“Logistics Report”);

return dialog;
}

Then you need the following few methods which will gather the project id and return it to the Dialog;

public boolean mustLoadSaveQuery()
{
;
return false;
}

private void setQueryEnableDS()
{
Query queryLocal = element.query();
;
}

private void setQueryRange(Common _common)
{
FormDataSource fds;

LogisticsControlTable logisticsTable;

QueryBuildDataSource qbdsLogisticsTable;
QueryBuildRange qbrProjId;
str rangeProjId;

set ProjIdSet = new Set(Types::String);

str addRange(str _range, str _value, QueryBuildDataSource _qbds, int _fieldNum, Set _set = null)
{
str ret = _range;
QueryBuildRange qbr;
;

if(_set && _set.in(_Value))
{
return ret;
}

if(strLen(ret) + strLen(_value) + 1 > 255)
{
qbr = _qbds.addRange(_fieldNum);
qbr.value(ret);
ret = ‘’;
}

if(ret)
{
ret += ‘,’;
}

if(_set)
{
_set.add(_value);
}

ret += _value;
return ret;
}
;

switch(_common.TableId)
{
case tableNum(LogisticsControlTable):

qbdsLogisticsTable = element.query().dataSourceTable(tableNum(LogisticsControlTable));
qbrProjID = qbdsLogisticsTable.addRange(fieldNum(LogisticsControlTable, ProjId));

fds = _common.dataSource();

for(logisticsTable = fds.getFirst(true) ? fds.getFirst(true) : _common;
logisticsTable;
logisticsTable = fds.getNext())
{
rangeProjId = addrange(rangeProjId , logisticsTable.ProjId, qbdsLogisticsTable, fieldNum(LogisticsControlTable, ProjId),logIdSet);
}

qbrLogisticsId.value(rangeProjId);
break;
}
}

// Check that ProjId field is correct on the LogisticsTable - I have used a different field…

public void run()
{
;
super();

this.setQueryEnableDS();
}

public void init()
{
;
super();

companyInfo = CompanyInfo::find();
if(element.args() && element.args().dataset())
{
this.setQueryRange(element.args().record());
}
}

Put these methods in your report Methods and then try running it from the form - now it will pick up the ProjId (project id).

I just need to select one record, and get project id from below table in the form. this report i am using for logistics and i wanted to add it to another form with different tables but with project Id field.

Then, add the menu item button to the form and link the menu item to the report?

Go into AOT → Forms → Browse to your form → Browse to the group you want the menu item on → Right-Click Add New Control → Choose Menu Item Button → and in the properties select the Menu Item Type (Output) and Menu Item Name (the report name which will be a menu item if it is already on a form).

Yes, i made the same, but it doesnt selects current record, and takes first record from table to report dialog.

Then, add the code I have given you to the report.

That code specifically tells the report to select the current record or record set that is highlighted, and pass the values as a range to the report dialog.

It is working corectly in logistics form, but not in second. Here is the code that is working in Logistics form:

public class ReportRun extends ObjectRun

{

DialogField dialogReportLanguageId;

LanguageId reportLanguageId;

container projIdsCon;

int rowNo;

boolean first;

InvoiceDate invoiceDate;

container otherNotes;

DataAreaId companyId;

#Define.CurrentVersion(2)

#LocalMacro.CurrentList

reportLanguageId

#EndMacro

}

//////////////

void initFromCaller(Args _args)

{

InventTransferId callerId;

QueryBuildDataSource queryBuildDataSource;

;

if (! _args ||

! _args.caller() ||

_args.dataset() != tablenum(GIR_Logistics) )

return;

callerId = _args.record().(fieldnum(GIR_Logistics, ProjId));

queryBuildDataSource = element.query().dataSourceTable(tablenum(GIR_Logistics));

if (! queryBuildDataSource.findRange(fieldnum(GIR_Logistics, ProjId)))

{

queryBuildDataSource.addRange(fieldnum(GIR_Logistics, ProjId));

}

queryBuildDataSource.findRange(fieldnum(GIR_Logistics, ProjId)).value(queryValue(callerId));

}

///////////////

boolean validate(Object calledFrom)

{

boolean ret = true;

;

if (reportLanguageId && !LanguageTable::exist(reportLanguageId))

{

ret = checkfailed(StrFmt("@GEE30055", reportLanguageId));

}

return ret;

}

//////////////

public boolean mustLoadSaveQuery()

{

return !conlen(projIdsCon);

}

/////////////

private void initFromArgs(Args args)

{

FormDataSource formDataSource;

GIR_Logistics logistics_args;

;

if( element.args() &&

element.args().dataset() &&

element.args().dataset() == tablenum(GIR_Logistics) &&

element.args().record().dataSource())

{

formDataSource = element.args().record().dataSource();

for(logistics_args = formDataSource.getFirst(true) ? formDataSource.getFirst(true): element.args().record();

logistics_args;

logistics_args = formDataSource.getNext())

{

projIdsCon += logistics_args.ProjId;

}

}

}

////////////////

public Query initQuery(Query _query)

{

QueryBuildDatasource qbdsLogistics;

QueryBuildRange qbrProjInvoiceId;

container subProjIdsCon;

int conI;

;

query = _query;

if(conlen(projIdsCon))

{

qbdsLogistics = element.query().dataSourceTable(tablenum(GIR_Logistics));

qbdsLogistics.clearRanges();

for(conI = 1; conI <= conlen(projIdsCon); conI++)

{

if(conlen(subProjIdsCon) >= 10)

{

qbrProjInvoiceId = qbdsLogistics.addRange(fieldnum(GIR_Logistics, ProjId));

qbrProjInvoiceId.value(con2str(subProjIdsCon, ‘,’));

subProjIdsCon = connull();

}

subProjIdsCon += conpeek(projIdsCon, conI);

}

if(conlen(subProjIdsCon))

{

qbrProjInvoiceId = qbdsLogistics.addRange(fieldnum(GIR_Logistics, ProjId));//

qbrProjInvoiceId.value(con2str(subProjIdsCon, ‘,’));

}

}

return query;

}

//////////////

public void run()

{

;

element.design().languageID(reportLanguageId);

super();

}

////////////

public boolean fetch()

{

boolean ret;

ret = super();

if(ret && !first)

{

if (conlen(otherNotes)) // RMT

{

element.execute(2);

}

else

{

element.execute(1);

}

}

return ret;

}

///////////

///Suiesko imone, su kuria pasirasyta logistikos apdorojimo sutartis

void findLogisticsCompany()

{

GIR_CustContract custContract;

;

////Imones informacija

custContract = GIR_CustContract::findByAgreementDate(GIR_Logistics.Orderer, GIR_Logistics.TerritoryInDate, GIR_AgreementType::Logistics);

if (custContract && custContract.CompanyId)

{

companyId = custContract.CompanyId;

}

else

{

companyId = curExt();

}

}

///////////

public void init()

{

;

first = true;

super();

this.initFromArgs(element.args());

}

//////////

public boolean send(Common _cursor, int _level=1, boolean _triggerOffBody=TRUE, boolean _newPageBeforeBody=FALSE)

{

boolean ret;

if(_cursor.TableId == tablenum(GIR_Logistics))

{

if(!first)

{

element.execute(1);

element.newPage();

rowNo = 0;

}

else

{

first = false;

}

}

ret = super(_cursor, _level, _triggerOffBody, _newPageBeforeBody);

return ret;

}

///////////

public void initParmDefault()

{

;

reportLanguageId = CompanyInfo::languageId();

}

///////////

public Object dialog(Object _dialog)

{

DialogRunbase dialog;

;

dialog = super(_dialog);

dialog.addGroup("@SYS7764");

dialogreportLanguageId = dialog.addFieldValue(typeId(GIR_LanguageId), reportLanguageId, “@SYS93120”, “@GEE30054”);

return dialog;

}

////////////

public boolean getFromDialog()

{

;

reportLanguageId = dialogReportLanguageId.value();

return true;

}

///////////

public container pack()

{

return [#CurrentVersion, #CurrentList];

}

/////////

public boolean unpack(container _packedClass)

{

boolean ret;

Version version = RunBase::getVersion(_packedClass);

switch (version)

{

case #CurrentVersion :

[version, #CurrentList] = _packedClass;

ret = true;

break;

default :

ret = false;

}

return ret;

}

So, What i should change, because in you example, there is no initFromArgs and InitQuery methods which i tried to change to anorther form.

thanks a lot.

What other form are you trying to run the report from?

With my example, I created a Logistics Job report, and I have this report on our Logistics Form and our Logistics List Page - on these two the report works fine for me.

Is the projId a field on this form? If not then it will be problematic as you need to get then go and find the ProjId based on whatever ID you can relate to from this other form.

orther form has above logistics_gluetask table with projId. The report needs to get that record projId

below form has logistics_salesTable with refProjId and it is some how related. But in report i need only projId to get it into the dialog.

And its enough to have one selected record, i dont need range.

Well the report should work on another form if the field is there, are you sure the field is on the same table?

Can’t suggest anything else sorry, would check which field the table sits in to make sure it is being picked up by the report methods.

Tables are different in these two forms, but both has the same projId field. I tried your code but it has some errors in it:

setQueryRange:

qbrLogisticsId.value(rangeProjId); - no such field in table says.

You need to change the fields to the correct fields, as I stated in the original post I did not use ProjId I used Logistics Id, so adapt the code to suit yourself with the correct field.

this thing solved my issue:

private void initFromArgs(Args args)

{

FormDataSource formDataSource;

GIR_Logistics logistics_args;

GIR_Logistics_GlueTask logistics_GlueTaskArgs;

GIR_Logistics_SalesTable logistics_SalesTable;

;

if( element.args() &&

element.args().dataset())

{

switch(element.args().dataset())

{

case tablenum(GIR_Logistics) :

formDataSource = element.args().record().dataSource();

for(logistics_args = formDataSource.getFirst(true) ? formDataSource.getFirst(true): element.args().record();

logistics_args;

logistics_args = formDataSource.getNext())

{

projIdsCon += logistics_args.ProjId;

}

break;

case tablenum(GIR_Logistics_GlueTask) :

formDataSource = element.args().record().dataSource();

for(logistics_GlueTaskArgs = formDataSource.getFirst(true) ? formDataSource.getFirst(true): element.args().record();

logistics_GlueTaskArgs;

logistics_GlueTaskArgs = formDataSource.getNext())

{

while select logistics_SalesTable group by refProjId

where logistics_SalesTable.GlueTaskId == logistics_GlueTaskArgs.GlueTaskId

{

projIdsCon += logistics_SalesTable.refProjId;

}

}

break;

}

}

}

Never seen it before but glad it fixed it.

I have another question. Can i take record from form to class dialog fields? it is not a report dialog.