Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically re-naming category labels in transformer model 1

Status
Not open for further replies.

atomictortoise

Programmer
Aug 9, 2001
9
GB
Hi All,

Has anyone got an example of a script that can dynamically change the labels in special time categories?

I have a special time category with child categories that are generated using a custom time calculation. I have currently got the category labels manually created eg.

Current Month -1
Current Month -2
Current Month -3 etc.

If the current month is March I need a script that can Label Current Month -1 as February Current Month -2 as January etc.

Any help much appreciated

Martin
 
Martin,
Assuming you're using CognosScript, it's pretty trivial.

I do something similar; here's some simplified code from one of my macros.

To generate the labels for the last 6 months
Code:
   tempdate = CVar(date)-Day(date)
   For x =6 to 1 step -1
   strmonth(x) = Format(CStr(tempdate),"Mmm YYYY")
   tempdate = tempdate - day(tempdate)
   next x

To substitute the labels
Code:
   Set objTransApp = CreateObject_("CognosTransformer.Application")
   Set objModel = objTransApp.OpenModel_("C:\models\model.pyi")
   Set objDimension = objModel.Dimensions.Item("All dates") 
   For x = 4 to 9
      Set objCategory = objDimension.Categories(x) 
      With objCategory
        .Name = strmonth(x-3)
        .Update
      End With
   Next x
   {rest of build script}

There are 3 existing standard date categories in my "All dates" date dimension; the FOR...NEXT loop changes the labels on items 4 to 9 to the last 6 months, the -3 being an adjustment to the array.

Remember the Update command.

Happy Friday,
Lex


soi la, soi carré
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top