Skip to Content
avatar image
Former Member

dynamically reference the name of a context attribute

Hi Experts

I would like to clean up the following code by putting it in a loop. Could someone show me how to dynamically reference the name of an attribute by substituting i for 1,2,3 and 4.

claimDetail.setAmount01(wdContext.currentDetailtabElement().getZz_Betrg_01());
claimDetail.setAmount02(wdContext.currentDetailtabElement().getZz_Betrg_02());
claimDetail.setAmount03(wdContext.currentDetailtabElement().getZz_Betrg_03());
claimDetail.setAmount04(wdContext.currentDetailtabElement().getZz_Betrg_04());

something like this

for (int i = 1; i <= 4; i++)

{

claimDetail.???

}

thanks in advance

Anton Kruse

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Feb 20, 2008 at 05:09 AM

    Hi,

    I think this is what you are looking for

    IWDNodeElement nodeElement; 
    	  List attributes = wdContext.getNodeInfo().getAttributes();
    	  for(int x=0; x < attributes.size(); x++)
    		  nodeElement.setAttributeValue(attributes.get(x), value);
    

    Regards

    Ayyapparaj

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      use as follows

      
      for (int x = 1; x < 4; x++)
      {
         claimDetail = wdContext.nodeClaimDetail().createClaimDetailElement();
         //wdContext.currentContextElement().getAttributeValue(attributeName);
         claimDetail.setAmount((BigDecimal)wdContext.currentDetailtabElement().getAttributeValue(getZz_Betrg_0 + "x" );
         wdContext.nodeClaimDetail().addElement(claimDetail);
      }
      
      

      Regards

      Ayyapparaj

  • avatar image
    Former Member
    Feb 20, 2008 at 07:43 AM

    Hi Anton,

    Simply use

    for( int i=1; i<= 4; i++)
    {
    //   claimDetail.setAmount01(wdContext.currentDetailtabElement().getZz_Betrg_01());
    
       claimDetail.setAttributeValue("Amount0" + i, wdContext.currentDetailtabElement().getAttributeValue("Zz_Betrg_0" + i) );
    }
    

    xxxxxxxxxxxxxxxxxx

    Regards

    Deepak

    Edited by: Armin Reichert on Feb 20, 2008 8:03 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2008 at 08:19 AM

    almost.

    I did it like this:

    claimDetail = wdContext.nodeClaimDetail().createClaimDetailElement();

    claimDetail.setAmount((BigDecimal)wdContext.currentDetailtabElement().getAttributeValue("Zz_Betrg_0" + i));

    wdContext.nodeClaimDetail().addElement(claimDetail);

    Add comment
    10|10000 characters needed characters exceeded