dynamically add fileds , tables , values and update in form dialog lookup (dicttable, dictfield)
Check SysQueryForm form logic reference
[Form]
public class NXR_TableFileldsUpdate extends FormRun
{
int selectedTableId;
int selectedFieldId;
Str1260 fieldValueStr;
RefRecId recIdValue;
int defaultTableId;
/// <summary>
///
/// </summary>
public void init()
{
super();
TableName.text("EDF_ContractLine");
SqlDictionary sqlDict;
Select tabId From sqlDict
Where sqlDict.name =="EDF_ContractLine"
&& sqlDict.fieldId==0;
selectedTableId = sqlDict.tabId;
defaultTableId = selectedTableId;
TableRecId.enabled(false);
}
private void executeAssetCrossCompanyLookup(
FormControl _formControl,
TableId _lookupTable,
FieldId _selectableLookupFiled,
container _lookupColumns,
container _companies)
{
SysTableLookUp lookUp;
Query lookupQuery = new Query();
QueryBuildDataSource lookupDataSource;
int i;
lookUp = SysTableLookup::newParameters(_lookupTable, _formControl);
for (i= 1; i <= conlen(_lookupColumns); i++)
{
lookUp.addLookupfield(conpeek(_lookupColumns, i));
}
lookUp.addSelectionField(_selectableLookupFiled);
lookupQuery.allowCrossCompany(true);
for (i= 1; i <= conlen(_companies); i++)
{
lookupQuery.addCompanyRange((conpeek(_companies, i)));
}
lookupDataSource = lookupQuery.addDataSource(_lookupTable);
lookUp.parmQuery(lookupQuery);
lookUp.performFormLookup();
}
/// <summary>
///
/// </summary>
public void updateRecord(RecId _recid)
{
ttsbegin;
Common common;
common = element.findRecord(selectedTableId,_recid, true);
if(!common.RecId)
{
throw Error("Record id value not found in related table");
}
else
{
common.(selectedFieldId) = fieldValueStr;
common.modifiedField(selectedFieldId);
common.update();
Info("updated");
}
ttscommit;
}
public Common findRecord(TableId _tableId, RecId _recId, Boolean _forUpdate = false)
{
Common common;
DictTable dictTable;
;
dictTable = new DictTable(_tableId);
common = dictTable.makeRecord();
common.selectForUpdate(_forUpdate);
select common
where common.RecId == _recId;
return common;
}
[Control("String")]
class TableName
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean modified()
{
boolean ret;
ret = super();
SqlDictionary sqlDict;
Select tabId From sqlDict
Where sqlDict.name ==TableName.text()
&& sqlDict.fieldId==0;
selectedTableId = sqlDict.tabId;
selectedFieldId = 0;
Edf_ContractId.text("");
LineNumber.realValue(0);
TableFieldNames.text("");
TableRecId.value(0);
FieldValue.text("");
Edf_ContractId.enabled(selectedTableId == defaultTableId );
LineNumber.enabled(selectedTableId == defaultTableId );
TableRecId.enabled(selectedTableId != defaultTableId );
return ret;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean validate()
{
boolean ret;
ret = super();
SqlDictionary sqlDict;
Select tabId From sqlDict
Where sqlDict.name ==TableName.text()
&& sqlDict.fieldId==0;
selectedTableId = sqlDict.tabId;
if(!selectedTableId)
{
ret = checkFailed("Table Id not found");
}
return ret;
}
}
[Control("String")]
class Edf_ContractId
{
/// <summary>
///
/// </summary>
public void lookup()
{
SysTableLookUp lookUp;
lookUp = SysTableLookup::newParameters(tableNum(EDF_ContractTable), this);
Query qr = new Query();
QueryBuildDataSource qbds = qr.addDataSource(tableNum(EDF_ContractTable));
lookUp.addLookupfield(fieldNum(EDF_ContractTable,ContractId),true);
lookUp.addLookupfield(fieldNum(EDF_ContractTable,Account));
lookUp.addLookupfield(fieldNum(EDF_ContractTable,AccountName));
lookUp.parmQuery(qr);
lookUp.performFormLookup();
}
}
[Control("String")]
class TableFieldNames
{
/// <summary>
///
/// </summary>
public void lookup()
{
SysTableLookUp lookUp;
lookUp = SysTableLookup::newParameters(tableNum(SqlDictionary), this);
Query qr = new Query();
QueryBuildDataSource qbds = qr.addDataSource(tableNum(SqlDictionary));
qbds.addRange(fieldnum(SqlDictionary,tabId)).value(SysQuery::value(selectedTableId));
qbds.addRange(fieldnum(SqlDictionary,fieldId)).value(SysQuery::valueNot(0));
lookUp.addLookupfield(fieldNum(SqlDictionary,name),true);
lookUp.addLookupfield(fieldNum(SqlDictionary,FieldId));
lookUp.parmQuery(qr);
lookUp.performFormLookup();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean modified()
{
boolean ret;
ret = super();
SqlDictionary sqlDict;
Select fieldId From sqlDict
Where sqlDict.name ==TableFieldNames.text()
&& sqlDict.tabId==selectedTableId;
selectedFieldId = sqlDict.fieldId;
FieldValue.text("");
return ret;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean validate()
{
boolean ret;
ret = super();
SqlDictionary sqlDict;
Select fieldId From sqlDict
Where sqlDict.name ==TableFieldNames.text()
&& sqlDict.tabId==selectedTableId;
selectedFieldId = sqlDict.fieldId;
if(!selectedFieldId)
{
ret = checkFailed("field Id not found");
}
return ret;
}
}
[Control("String")]
class FieldValue
{
/// <summary>
///
/// </summary>
public void lookup()
{
element.executeAssetCrossCompanyLookup(
this,
selectedTableId,
selectedFieldId,
[selectedFieldId],
[curExt()]);
}
}
[Control("CommandButton")]
class OkButton
{
/// <summary>
/// Runs the DOM processor with selected order type and shipping type.
/// </summary>
public void clicked()
{
super();
fieldValueStr = FieldValue.text();
recIdValue = TableRecId.value();
if(selectedTableId && selectedFieldId && fieldValueStr)
{
if(selectedTableId == defaultTableId)
{
EDF_ContractId contractIdStr = Edf_ContractId.text();
EDF_LineNum contractLineNum = LineNumber.realValue();
EDF_ContractLine contractLine = EDF_ContractLine::findByLine(contractIdStr,contractLineNum,true);
if(contractLine)
{
element.updateRecord(contractLine.RecId);
}
else
{
throw Error(" contract line not found ");
}
}
else if(recIdValue)
{
element.updateRecord(recIdValue);
}
else
{
throw Error(" Mandatory values missing ");
}
}
else
{
throw Error(" Mandatory values missing ");
}
}
}
}
Comments
Post a Comment