Run time add form controls (dynamic) - active financial dimensions dialog form
[Form]
public class HIGUpdateFinDimFromSalesHeaderToLines extends FormRun
{
CustInvoiceTable custInvoiceTable;
List finLi,selectedFinLi;
FormBuildDesign formBuildDesign;
void closeOk()
{
if(!custInvoiceTable.DefaultDimension)
{
throw Error("Dimensions not found on header");
}
else if( custInvoiceTable.InvoiceId)
{
throw Error("Changes cannot be made for invoiced orders");
}
else
{
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionDefault result;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DirPartyName attrName;
FormCheckBoxControl fcbcSelect;
selectedFinLi = new List(Types::String);
ListEnumerator liEnum = finLi.getEnumerator();
while(liEnum.moveNext())
{
attrName = liEnum.current();
fcbcSelect = element.design().controlName(attrName);
if(fcbcSelect.checked())
{
dimensionAttribute = dimensionAttribute::findByName(attrName);
dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,element.getDimensionValueTEC(custInvoiceTable.DefaultDimension,attrName),false,false);
if(dimensionAttributeValue)
{
valueSetStorage.addItem(dimensionAttributeValue);
}
}
}
result = valueSetStorage.save();
if(result)
{
ttsbegin;
CustInvoiceLine custInvoiceLine;
while select forupdate custInvoiceLine
where custInvoiceLine.ParentRecId == custInvoiceTable.RecId
{
custInvoiceLine.DefaultDimension = result;
custInvoiceLine.doUpdate();
}
ttscommit;
#Task
FormRun fr = element.args().caller();
fr.task(#TaskRefresh);
Info("financial dimensions has been updated in lines");
}
}
super();
}
public str 255 getDimensionValueTEC(RecId defaultDimension, Name dimName)
{
DimensionAttributeValueSetStorage dimStorage;
Counter i;
DimensionAttribute dimAttributeCostCenter;
DimensionAttributeValue dimAttributeValue;
dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
}
public void init()
{
finLi = new List(Types::String);
// element.addControls();
if(element.args().dataset() == tableNum(CustInvoiceTable))
{
custInvoiceTable =element.args().record();
}
super();
}
public void addControls()
{
FormBuildGroupControl formBuildGroupControl;
FormCheckBoxControl fcbc;
FormBuildGroupControl formGroupControl;
formBuildDesign = element.form().design();
// formGroupControl = formBuildDesign.addControl(FormControlType::Group, "FinDimGroup") ;
// formGroupControl.caption("Finanical dimensions");
DimensionAttributeSetItem dimAttrItemSet;
DimensionAttribute dimAttrList;
DimensionAttribute dimAttr;
DimensionattributeSetItem dimAttrSetItem;
DimensionEnumeration dimensionSetId;
int dimAttrCount;
dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger();
select count(RecId) from dimAttr
where dimAttr.Type != DimensionAttributeType::MainAccount
join RecId from dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
dimAttrSetItem.DimensionAttributeSet == dimensionSetId;
while select * from dimAttr
order by Name
where dimAttr.Type != DimensionAttributeType::MainAccount
join RecId from dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
dimAttrSetItem.DimensionAttributeSet == dimensionSetId
{
finLi.addEnd(dimAttr.Name);
fcbc = FinDimGroup.addControl(FormControlType::CheckBox,dimAttr.Name);
fcbc.label(dimAttr.Name);
}
}
/// <summary>
///
/// </summary>
public void run()
{
element.addControls();
super();
}
}
Comments
Post a Comment