javascript function code improvement

I’m looking to improve a function call that returns a file name based on three args that are passed.

arg data examples of category, rptGroup & rptItem:

category    rptGroup    rpItem      
Flash             g1           RptItem1
Flash             g1           RptItem2
Flash             g3           RptItem7
Demand       g5           RptItem6

category   > 1-m rptGroups
rptGroups > 1-m rptItems

variables store the file names (var naming represents the category (f = flash, d = demand, etc.), group (g1 = group1, etc.) and report item # which is sequential within a category/group):

var fg1RptItem1 = '/flashgroup1rpt1.pdf';    
var fg1RptItem2 = '/ flashgroup1rpt2.pdf';
var fg2RptItem1 = '/flashgroup2rpt1.pdf';  
var dg1RptItem1 = '/demandgroup1rpt1.pdf';    
var dg1RptItem2 = '/demandgroup1rpt2.pdf';    

Call example:

var category = ‘Flash’;
var rptGroup = ‘g1’;
var rptItem   = ‘RptItem1’;


returns:  rptItem =  '/flashgroup1rpt1.pdf'

function GetFilename(category,rptGroup,rptItem)
   switch(parentCategory+'|'+rptGroup) {

    case 'Flash|g1' :
    //Return appropriate value based on rptItem
    switch(rptItem) {
       case 'RptItem1' : rptItem = fg1RptItem1; break;
       case 'RptItem2' : rptItem = fg1RptItem2; break;  
    } ; break;

    case 'Flash|g2' :
    switch(rptItem) {
       case 'RptItem1' : rptItem = fg2RptItem1; break;
       case 'RptItem2' : rptItem = fg2RptItem2; break;  
       case 'RptItem3' : rptItem = fg2RptItem3; break;  
    } ; break;

    case 'Demand|g1' :
    switch(rptItem) {
       case 'RptItem1' : rptItem = dg1RptItem1; break;
       case 'RptItem2' : rptItem = dg1RptItem2; break;  
    }; break;
   return rptItem;  //returns report file name i.e. '/flashgroup1rpt1.pdf'

Suggestions of an improvement (loop, array, ?) along with a code snippet example based on the above example would be greatly appreciated!

Thank you!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
Perhaps this?


var myArgs = {
    Flash: {
        g1: {
        g2: {
    Demand :{
        g1: {

function GetFilename(category,rptGroup,rptItem) {
   return myArgs[category][rptGroup][rptItem]+'.pdf';

var category = "Flash";
var rptGroup = "g1";
var rptItem  = "RptItem1";


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ssebringAuthor Commented:
can't thank you enough!  This is an elegant solution that has opened all sorts of shortcuts in the existing code.  Looks like it will be a great way to go with this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.