How to insert a main column

I open up a module, save the existing columns, delete these columns, perform some filtering activity, then turn the filter and want to restore the original columns.

I am having difficulty with the Main column.
I am getting an unknown attribute error for the main column.

Any suggestions?

Thank you

Here is my code:
 

strNewLine = "\n"
strBlank = ""
const int nTestStatus = 0
const int nOriginalColumns = 0
Column gColumnToModify = null
string strColorAttr = "null"
string strTS = "Test Status"
string strTC = "Test Comment"
bool bColumnFound = false
Module m = current
AttrDef ad
int nColumnToDeleteAndAddBack
Column Original[20]
const string strOriginalColumnTitle[] = {"","","","","","","","","","","","","","","","","","","",""}  // 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
const string strOriginalColor[] = {"","","","","","","","","","","","","","","","","","","",""}  // 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
int nMainColumn
const int MAX_COLUMNS = 4
const string strColumnTitle[] = {"Base ID","VV Test Identifier","",strTC}  // 0,1,2,3
void OriginalColumns()
{
        int nCount = 0
 
        Column col
        for ad in m do
        {
           if ((ad.object) && (!ad.system)) 
           {
                col = column (nCount)
                if (main(col))
                        nMainColumn = nCount
                Original[nCount] = col
                strOriginalColumnTitle[nCount] = title(col) 
                strOriginalColor[nCount] = color(col)
                nCount++
           } // end if ((ad.object) && (!ad.system)) 
        } // end for ad in m do
        int nLoop
        for (nLoop = 0; nLoop < nCount; nLoop++)
        {
                if (strOriginalColumnTitle[nLoop] != strBlank)
                {
                 //print "Column " Original[nLoop] strNewLine
                       // print "Title " strOriginalColumnTitle[nLoop] strNewLine
                       // print "Color " strOriginalColor[nLoop] strNewLine
                       // print strNewLine
                        nOriginalColumns = nLoop
                } // end if (strOriginalColumnTitle != strBlank)
        } // end for (int nLoop = 0; nLoop < nCount; nLoop++)
} // OriginalColumns()
void DeleteOriginalColumns()
{
        int n = 0       // number of existing columns 
        int i           // column index 
        Column c 
        for c in current Module do 
        n++ // count the columns 
        // delete n column 0s 
        for i in 1:n do
        {
                delete column 0
        }  // end for i in 1:n do
} //DeleteOriginalColumns()
void ReplaceOriginalColumns()
{
        int nLoop
        print "Original Columns " nOriginalColumns strNewLine
        for (nLoop = 0; nLoop < nOriginalColumns; nLoop++)
        {
                //Column col = Original[nLoop]
                Column col
                string strTitle = strOriginalColumnTitle[nLoop]
                string strColor = strOriginalColor[nLoop]
                col = insert (column nLoop)
                if (nLoop == nMainColumn)
                        main(col)
                attribute(col, strTitle)
                // Copy the column color, if it exists
                if( !null strColor )
                {
                        color( col, strColor)
                } // end if( !null strColorAttr )
                width(col, 100)
        }  // end for (nLoop = 0; nLoop < nOriginalColumns; nLoop++)
}  //ReplaceOriginalColumns()
pragma runLim, 0                                           //disables the "Execution Timeout" dialog
OriginalColumns
DeleteOriginalColumns
ReplaceOriginalColumns

Gedinfo - Fri May 18 09:18:44 EDT 2012

Re: How to insert a main column
SystemAdmin - Fri May 18 10:12:58 EDT 2012

Do not insert any attributes to the main column, only in "real" attribute columns.

  • Pekka Mäkinen - http://www.softqa.eu/

Re: How to insert a main column
Gedinfo - Fri May 18 10:44:24 EDT 2012

I have removed the attribute for main.

Now, I do not get the error message, but I do not get the main column to appear, nor the additional column following it.
 

void ReplaceOriginalColumns()   
{
        int nLoop
        print "Original Columns " nOriginalColumns strNewLine
        for (nLoop = 0; nLoop < nOriginalColumns; nLoop++)
        {
                //Column col = Original[nLoop]
                Column col
                string strTitle = strOriginalColumnTitle[nLoop]
                string strColor = strOriginalColor[nLoop]
                col = insert (column nLoop)
                if (nLoop != nMainColumn)
                        attribute(col, strTitle)
                // Copy the column color, if it exists
                if( !null strColor )
                {
                        color( col, strColor)
                } // end if( !null strColorAttr )
                width(col, 100)
        }  // end for (nLoop = 0; nLoop < nOriginalColumns; nLoop++)
}  //ReplaceOriginalColumns()

Re: How to insert a main column
llandale - Fri May 18 12:18:28 EDT 2012

First off, the column is EITHER main OR an attribute:
  • if (nLoop == nMainColumn) //
  • then main(col)
  • else attribute(col, strTitle)

Second, you will need to ignore or replicate Layout columns. I think this may get you going:
  • string attName = attrName(srcCol)
  • string DxlCode = dxl(srcCol)
  • if (!null(attName)) then this column displays this attribute
  • elseif(main(srcCol)) then this is the main column
  • elseif(!null DxlCode) then this is a layout column
  • else Louie has more to learn

Third, what's the point? Just do your filter. If you must do this, then if the view does not remember the filter then just apply your filter and re-load the view.

-Louie

Re: How to insert a main column
Gedinfo - Fri May 18 12:28:10 EDT 2012

The point behind this is that there are many people on my team that benefit from a script automating this process. The main reason is to create a filter of columns in a certain order to be exported into a spreadsheet. One script means consistency with the spreadsheet information.

Each team member has set up views that are not always how the spreadsheet expects, therefore, I save the existing columns, delete them, display required columns, export to spreadsheet, then delete the required, and redisplay the view.

Re: How to insert a main column
llandale - Fri May 18 14:35:47 EDT 2012

Gedinfo - Fri May 18 12:28:10 EDT 2012
The point behind this is that there are many people on my team that benefit from a script automating this process. The main reason is to create a filter of columns in a certain order to be exported into a spreadsheet. One script means consistency with the spreadsheet information.

Each team member has set up views that are not always how the spreadsheet expects, therefore, I save the existing columns, delete them, display required columns, export to spreadsheet, then delete the required, and redisplay the view.

Again, you can simply just reload the view that is displayed when the script starts. May not be perfect, but who cares.

Would it not just be easier to define such an export-view and have your script load it, along with its filter? Then you load the view and exort. That just has to be superior to hard-coding all that info in a script.

-Louie