I need to show a Defaulted value in CostCenter Lookup field in Transfer To Financial Dimension Section in form Asset Transfer.
I have tried to get it done but it does not work.
I have written code on oninitialize of Assetbook Table using class , it did not work below:
internal final class OnInitializedAssetBookHex
{
/// <summary>
///
/// </summary>
/// <param name=/sender/></param>
/// <param name=/e/></param>
[FormDataSourceEventHandler(formDataSourceStr(AssetTransfer, AssetBook), FormDataSourceEventType::InitValue)]
public static void AssetBook_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
{
/* FormRun formRun = sender.formRun();
FormStringControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
alternateItemGroup.text('Fashion');
formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader)).allowEdit(false);*/
}
/// <summary>
///
/// </summary>
/// <param name=/sender/></param>
/// <param name=/e/></param>
[FormDataSourceEventHandler(formDataSourceStr(AssetTransfer, AssetTmpAssetTransferHistory), FormDataSourceEventType::Initialized)]
public static void AssetTmpAssetTransferHistory_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
/*FormRun formRun = sender.formRun();
FormStringControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
//alternateItemGroup.text('test');
formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader)).allowEdit(false);*/
}
/// <summary>
///
/// </summary>
/// <param name=/sender/></param>
/// <param name=/e/></param>
[FormDataSourceEventHandler(formDataSourceStr(AssetTransfer, AssetBook), FormDataSourceEventType::Initialized)]
public static void AssetBook_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
DimensionEntryControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
//FormStringControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
//alternateItemGroup.setDimensionAttributeValue('test');
// alternateItemGroup.setDimensionAttributeValue(DimensionAttribute::findByName(/CostCenter/),'125');
DimensionAttribute dimensionAttribute = DimensionAttribute::findByName(/CostCenter/);
// DimensionAttributeValueSet dimensionAttributeValueSet = DimensionAttributeValueSet.RecId where DimensionAttributeValueSet.
// DimensionAttribute dimensionAttribute = DimensionAttribute::findByLocalizedName
alternateItemGroup.setDimensionAttributeValue(dimensionAttribute,'100');
// alternateItemGroup.displayControl();
// alternateItemGroup.parmDisplayValues(true);
//alternateItemGroup.saveAttributeValueSet();
formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader)).allowEdit(false);
}
}
I have also tried writting on INIT of form AssetTransfer using for extension still did not work as below:
public void init()
{
// FormRun formRun;
FormControl control;
DimensionDefault defaultDimension;
// DimensionAttributeValueSetItem dimAttrValueSetItem;
DimensionAttributeValue dimAttrValue;
// DimensionAttribute dimAttr = DimensionAttribute::findByName(#DimensionName);
str dimensionValue,assetId,dimValue,valueToAssign;
Random random = new Random();
FormStringControl assetTmpAssetTransferHistory_DimensionValue,assetTable_AssetId;
HEX_FATransferIntegrationLog hex_FATransferIntegrationLog;
next init();
MultiSelectionContext multiSelectionContext = this.args().multiSelectionContext();
AssetTable localAssetTable = multiSelectionContext.getFirst() as AssetTable;
boolean isEditable;
select firstonly hex_FATransferIntegrationLog
where hex_FATransferIntegrationLog.AssetId == localAssetTable.AssetId;
if(!hex_FATransferIntegrationLog)
{
this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(false);
// this.design().controlName(formControlStr(AssetTransfer, SendForApproval)).labelText(
}
if(hex_FATransferIntegrationLog && hex_FATransferIntegrationLog.Approved == NoYes::No)
{
this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(false);
SendForApproval.text(/Pending for approval/);
// dimAttrValueSetItem.DisplayValue = hex_FATransferIntegrationLog.ToAsset;
// form.design(0).controlName(/DimensionEntryControlHeader/) = hex_FATransferIntegrationLog.ToAsset;
}
else if(hex_FATransferIntegrationLog && hex_FATransferIntegrationLog.Approved == NoYes::Yes)
{
this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(true);
this.design().controlName(formControlStr(AssetTransfer, SendForApproval)).visible(false);
//VT
FormRun formRun = this.args().caller();
DimensionEntryControl dimensionEntryControl = formRun.design().controlName(/DimensionEntryControlHeader/);
str dimensionName = /Costcenter/;
str costCenterValue = /YourCostCenterValue/; // Replace this with the actual value you want to assign
// Find the CostCenter dimension attribute
DimensionAttribute dimensionAttribute = DimensionAttribute::findByName(dimensionName);
if (dimensionAttribute)
{
// Find the DimensionAttributeValue corresponding to the given CostCenter value
DimensionAttributeValue dimensionAttributeValue;
select firstonly dimensionAttributeValue
where dimensionAttributeValue.DisplayValue == costCenterValue
&& dimensionAttributeValue.DimensionAttribute == dimensionAttribute.RecId;
if (dimensionAttributeValue)
{
// Create a new DimensionAttributeValueSetStorage instance
DimensionAttributeValueSetStorage dimensionStorage;
// Add the DimensionAttributeValue to the DimensionAttributeValueSetStorage
dimensionStorage.addItem(dimensionAttributeValue.RecId);
// Save the DimensionAttributeValueSetStorage to the DimensionEntryControl
dimensionEntryControl.saveAttributeValueSet(dimensionStorage);
}
else
{
// If the CostCenter value doesn't exist, handle the case accordingly.
// For example, you might create the dimension value or show an error message.
error(/CostCenter value not found!/);
}
}
else
{
error(/CostCenter dimension attribute not found!/);
}
// VT
}
}
Please help me write the correct code and at correct palce to set a prefixed default value in that field.
I have also Attached the screenshot of where i need that value for better reference.

Thanks
Varun