Search This Blog

Thursday, September 8, 2011

Search Fields Based on EDT with Extends functionality

I posted the sample code previously which will get the only that EDT Used fields.
http://krishhdax.blogspot.com/2011/09/search-fields-list-based-on-edt.html

The following  sample code used to find the fields till base EDT level.
Example FieldSample-with Extends EDTB->extends EDTA.
If we provide EDTA this code will search all fields used by EDTB and EDTA

static void krishh_FindFieldsTillBaseEDT(Args _args)
{
    Dictionary dictionary = new Dictionary();
    DictTable dictTable;
    DictField dictField;
    DictType dictType;
    Dialog                  dialog              = new Dialog('Search Fields based on EDT');
    DialogField             dialogEDTName     = dialog.addField(typeid(Name),'EDT Name');
    Int cntDict;
    Int cntFlds;
    int i;
    Str EDTName;
    UtilElements  utilElements;
    ExtendedTypeId extendTypeId;
    boolean validate=false;
    ;
    if (dialog.run())
    {
        EDTName = dialogEDTName.value();
    }
    dialog.close();
    if(EDTName=="")
     return;
    /* looping through tables */
    for (cntDict=1; cntDict<=dictionary.tableCnt();cntDict++)
    {
        dictTable = new DictTable(dictionary.tableCnt2Id(cntDict));
        select count(recid)              from utilElements
        where (utilElements.parentId    == tablename2Id(dictTable.name())              &&
              (utilElements.utilLevel   == UtilEntryLevel::var                           ||
               utilElements.utilLevel   == UtilEntryLevel::cus));
        if(utilElements.recid>0)
        {
           /* looping through fields */
            for (cntFlds=1; cntFlds<=dictTable.fieldCnt();cntFlds++)
            {
                dictField = new DictField(dictTable.id(),dictTable.fieldCnt2Id(cntFlds));
                dictType = new DictType(dictField.typeId());
                if (dictField.type()==Types::UserType)
                {
                    select name, utilLevel
                    from utilElements
                    where (utilElements.parentId    == tablename2Id(dictTable.name())   &&
                           utilElements.name== DictField.name())                        &&
                          (utilElements.recordType  == UtilElementType::TableField)     &&
                          (utilElements.utilLevel   == UtilEntryLevel::var              ||
                           utilElements.utilLevel   == UtilEntryLevel::cus);
                    if(utilElements.name)
                    {
                        while(true)
                        {
                            extendTypeId=dictType.extend();
                            if(extendTypeId==0)
                            {
                              if(dictType.name() like EDTName)
                              {
                               validate=true;
                              }
                              break;
                            }
                            else
                            {
                                dictType = new DictType(extendTypeId);
                            }
                        }
                        if(validate)
                        {
                            info('================================');
                            info('Table Name:      ' + dictTable.name  ());
                            info(strfmt('Field Name:%1 Layer:%2',  dictField.name(),utilElements.utilLevel));
                            info('Base Type:   ' + Enum2Str(dictField.baseType()));
                            info('EDT Type Name: ' + dictType.name());
                            validate=false;
                        }
                    }
                }
            }
        }
    }
}

No comments:

Post a Comment

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.