Dec 28, 2015

Financial Dimension on Dialog through SysOperationFrameWork

 ===========================Contract Class================================
[
    DataContractAttribute,
    SysOperationContractProcessingAttribute(classstr(FindimUpUIBuilder), SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)
]
public class CVRRentalDueDateReminderContract
{
    int numberOverdueDays;
    int overrideNumOfDays;
    str packedQuery;
    Name primaryDimensionFocus;
    // string value of range
    SerializedDimensionRange    serializedDimensionRanges;
    FreeText                    dimensionRange;
    InventDimViewContract       inventdimViewContract;

}


public Query getQuery()
{
    return new Query(SysOperationHelper::base64Decode(packedQuery));

}

[
    DataMemberAttribute(identifierStr(DimensionRange))
]
public FreeText parmDimensionRange(FreeText _dimensionRange = dimensionRange)
{
    dimensionRange = _dimensionRange;
    return dimensionRange;

}

public Map parmDimensionRangeMap(Map _dimensionRangeMap = null)
{
    XmlDocument xDoc;
    Map dimRangeMap;

    if (prmisDefault(_dimensionRangeMap))
    {
        if (serializedDimensionRanges)
        {
            xDoc = new XmlDocument();
            xDoc.loadXml(serializedDimensionRanges);

            dimRangeMap = Map::createFromXML(xDoc.root() as XmlNode);
        }
        else
        {
            dimRangeMap = new Map(Types::Int64, Types::String);
        }
    }
    else
    {
        if (_dimensionRangeMap == null)
        {
            _dimensionRangeMap = new Map(Types::Int64, Types::String);
        }
        else
        {
            this.parmSerializedDimensionRanges(_dimensionRangeMap.xml());
        }
        dimRangeMap = _dimensionRangeMap;
    }
    return dimRangeMap;
}



[DataMemberAttribute('InventDimViewContract')]
public InventDimViewContract parmInventDimViewContract(InventDimViewContract _inventDimViewContract = inventDimViewContract)
{
    inventDimViewContract = _inventDimViewContract;
    return inventDimViewContract;
}

 
[DataMemberAttribute('OverdueDays'),
SysOperationDisplayOrderAttribute('2')]
public int parmNumberOverdueDays(int _numberOverdueDays = numberOverdueDays)
{
;
    numberOverdueDays = _numberOverdueDays;
    return numberOverdueDays;
}

[DataMemberAttribute('OverrideNumOfDays'),
SysOperationDisplayOrderAttribute('1')]
public int parmOverrideNumOfDays(int _overrideNumOfDays = overrideNumOfDays)
{
    overrideNumOfDays = _overrideNumOfDays;
    return overrideNumOfDays;
}


[   DataMemberAttribute('PrimaryDimensionDimensionFocus'),
    SysOperationLabelAttribute(literalstr("@SYS329752")),
    SysOperationHelpTextAttribute(literalstr("@SYS307658")),
    SysOperationDisplayOrderAttribute('3')
]
public Name parmPrimaryDimensionFocus(Name _primaryDimensionFocus = primaryDimensionFocus)
{
    primaryDimensionFocus = _primaryDimensionFocus;
    return primaryDimensionFocus ;// ? primaryDimensionFocus : "MA+BU+DEPT" ;
}

 

[DataMemberAttribute,
AifQueryTypeAttribute('_packedQuery', querystr(CustTable))]
public str parmQuery(str _packedQuery = packedQuery)
{
;
    packedQuery = _packedQuery;
    return packedQuery;
}
 

[
    DataMemberAttribute(identifierStr(SerializedDimensionRanges))
]
public SerializedDimensionRange parmSerializedDimensionRanges(SerializedDimensionRange _serializedDimensionRanges = serializedDimensionRanges)
{
    serializedDimensionRanges = _serializedDimensionRanges;
    return serializedDimensionRanges;
}


public void setQuery(Query _query)
{
    packedQuery = SysOperationHelper::base64Encode(_query.pack());
}

===========================Service Class==================================

public class CVRRentalDueDateReminderService extends SysOperationServiceController
{
}


[SysEntryPointAttribute(true)]
public void checkDueDates(CVRRentalDueDateReminderContract _dueDateReminderContract)
{
    QueryRun      queryRun;
    CustTable     custTable;
    Map           dimensionRangeMap;
    MapEnumerator rangeMapEnumerator;
    RecId         dimAttrRecId;
    str           dimensionCriteria;



    dimensionRangeMap = _dueDateReminderContract.parmDimensionRangeMap();

     rangeMapEnumerator = dimensionRangeMap.getEnumerator();

     while (rangeMapEnumerator.moveNext())
    {
         dimAttrRecId = rangeMapEnumerator.currentKey();
        dimensionCriteria = rangeMapEnumerator.currentValue();
        info(dimensionCriteria);

    }
    // Get the query from the data contract
    queryRun = new QueryRun(_dueDateReminderContract.getQuery());

    while (queryRun.next())
    {
        custTable = queryRun.get(tableNum(CustTable));
        info(custTable.AccountNum + "Name = " + custTable.name());

    }
}




public CVRRentalDueDateReminderContract getCVRRentalDueDateReminderContract()
{
    return this.getDataContractObject('_CVRRentalDueDateReminderContract') as CVRRentalDueDateReminderContract;
}

public static CVRRentalDueDateReminderService construct()
{
    return new CVRRentalDueDateReminderService();
}

public static void main(Args _args)
{
    identifierName                         className, methodName;
    SysOperationExecutionMode              mode;
    CVRRentalDueDateReminderContract  contract;
    CVRRentalDueDateReminderService  reminderService ;//= CVRRentalDueDateReminderService::construct();

    [className, methodName, mode] = SysOperationServiceController::parseServiceInfo(_args);
    reminderService                    = new CVRRentalDueDateReminderService(className, methodName, mode);

    reminderService.parmDialogCaption("Vivek Testing for fin Dimension");
    contract = reminderService.getDataContractObject('CVRRentalDueDateReminderContract');
    reminderService.startOperation();
}

=========================UI Builder Class=================================


public class FindimUpUIBuilder extends SrsReportDataContractUIBuilder
{

    CVRRentalDueDateReminderContract  contract;

    DialogField dialogFieldPrimaryFocus;
    DialogGroup dialogDimensionsGroup;
    DialogField dialogFieldDetailLevel;
    Map     dimControlsMap;
    Map dimControlMap;
    Map dimRangeMap;
}

public void build()
{
     DialogField                 dimField;
    str                         thisVal;
    str                         thisLabel;
    DimensionAttributeSetItem   dimensionAttributeSetItem;
    DimensionAttribute          dimensionAttribute;
    DimensionEnumeration        dimAttrSetForLedger;
    super();
    contract = this.dataContractObject() as CVRRentalDueDateReminderContract;

    dialogDimensionsGroup = this.dialog().addGroup("@GLS101565");
    dialogDimensionsGroup.hideIfEmpty(false);

    dialogDimensionsGroup = this.dialog().addGroup("@GLS101565");
    dialogDimensionsGroup.hideIfEmpty(false);

        // Control map maps dimension attributes to physical controls
        dimControlMap = new Map(Types::Int64, Types::Class);

        // DimRangeMap map dimension attributes to ranges
       // dimRangeMap = contract.parmDimensionRangeMap();
        dimAttrSetForLedger = DimensionCache::getDimensionAttributeSetForLedger();

        while select DimensionAttribute from dimensionAttributeSetItem where dimensionAttributeSetItem.DimensionAttributeSet == dimAttrSetForLedger
            join * from dimensionAttribute where dimensionAttribute.RecId == dimensionAttributeSetItem.DimensionAttribute
        {
               //  thisVal = DimensionAttribute::find(dimensionAttributeSetItem.DimensionAttribute).Name;

                thisVal = '';

            thisLabel = dimensionAttribute.localizedName();

            dimField = this.dialog().addFieldValue(extendedTypeStr(String255), thisVal, thisLabel);
            dimField.registerOverrideMethod(methodstr(FormStringControl, lookup), methodstr(LedgerTrialBalanceUIBuilder, lookupDimensionAttribute), this);

            dimControlMap.insert(dimensionAttributeSetItem.DimensionAttribute, dimField);
        }
        //IfFin dim show based on dimension set you should pass set name in below parm
         this.updateForFocus(contract.parmPrimaryDimensionFocus());
}
///
/// Implements a custom lookup for dimension attribute.
///
///
/// The FormStringControl for which the lookup fields must be associated.
///
///
/// It uses the DimensionAttribute table for lookup.
///
private void lookupDimensionAttribute(FormStringControl _dimensionValue)
{
    Args                    e;
    FormRun                 lookupFormRun;
    DimensionAttribute      dimAttr;
    Object                  object;

    if (_dimensionValue != null)
    {
        // Construct arguments for the custom lookup
        e = new Args();
        e.name(formStr(DimensionDefaultingLookup));
        e.lookupValue(_dimensionValue.text());
        e.caller(_dimensionValue);

        // Find the dimension attribute associated with the string control which called this method
        dimAttr = DimensionAttribute::findByLocalizedName(_dimensionValue.label());
        e.lookupField(dimAttr.ValueAttribute);
        e.record(dimAttr);

        // Run the custom lookup and init the lookup form
        lookupFormRun = classfactory.formRunClass(e);
        lookupFormRun.init();

        // Specify this is the callback on the lookup form by casting the
        // form to an object and late binding the setResultCallback method
        if (SysFormRun::hasMethod(lookupFormRun, identifierStr(setResultCallback)))
        {
            object = lookupFormRun;
            object.setResultCallback(this);
        }

        _dimensionValue.performFormLookup(lookupFormRun);
    }
}

///
/// Override this method in order to register the dialog field methods to capture events.
///
public void postRun()
{
    DialogField dialogFieldSecondaryFocus;
    Dialog dialogLocal = this.dialog();

    super();

    // This method should be called in order to handle events on dialogs.
   // dialogLocal.dialogForm().formRun().controlMethodOverload(false);

    // dimension sets
   // dialogFieldPrimaryFocus = this.bindInfo().getDialogField(this.dataContractObject(), methodstr(LedgerTrialBalanceContract, parmPrimaryDimensionFocus));
   // dialogFieldPrimaryFocus.registerOverrideMethod(methodstr(FormStringControl, lookup), methodstr(LedgerTrialBalanceUIBuilder, dimensionSetLookup), this);
   // dialogFieldPrimaryFocus.registerOverrideMethod(methodstr(FormStringControl, modified), methodstr(LedgerTrialBalanceUIBuilder, dimensionSetModified), this);
}

public void setDimensionAttributeValue(DimensionAttribute _dimensionAttribute, RecId _dimAttrValueRecId, str _value)
{
    // Force a save of the set(s) as the user may leave the tab at any point and no event will be raised to force a savedimControlMap
}
 
///
/// Updates the dialog fields for the dimension hierarchy.
///
///
/// The dimension hierarchy name.
///
public void updateForFocus(Name _dimensionHierarchyName = '')
{
    RecId                   dimHierarchyRecId;
    MapEnumerator           controlMapEnumerator;
    DimensionHierarchyLevel dimHierarchyLevel;
    boolean                 setHasDimension;
    DialogField             dimField;
    RecId                   dimAttrRecId;
    boolean                 anyDimensionsVisible;

     dimHierarchyRecId = DimensionHierarchy::findByTypeAndName(DimensionHierarchyType::Focus, _dimensionHierarchyName).RecId;

        // Clear out existing dialog fields
        controlMapEnumerator = dimControlMap.getEnumerator();
        while (controlMapEnumerator.moveNext())
        {
            dimAttrRecId = controlMapEnumerator.currentKey();
            dimField = controlMapEnumerator.currentValue();

            setHasDimension = false;

            if (dimHierarchyRecId)
            {
                    select firstOnly RecId from dimHierarchyLevel where
                        dimHierarchyLevel.DimensionHierarchy == dimHierarchyRecId &&
                        dimHierarchyLevel.DimensionAttribute == dimAttrRecId;

                setHasDimension = (dimHierarchyLevel.RecId != 0);
            }
            else
            {
                 select firstOnly RecId from dimHierarchyLevel where
                        dimHierarchyLevel.DimensionAttribute == dimAttrRecId;

                setHasDimension = (dimHierarchyLevel.RecId != 0);
            }

            dimField.visible(setHasDimension);
            anyDimensionsVisible = anyDimensionsVisible || setHasDimension;
        }

        dialogDimensionsGroup.visible(anyDimensionsVisible);

}

 

 

No comments: