Skip to main content

Notifications

Finance forum
Suggested answer

Variable scope

Posted on by 134
Hi, 
 
In my DP class, I have one void called ProcessReport, and inside I declared the contract class. Inside this void, I need to call another void process, how to declare the contract variable class, so it will be recognize in the 2nd void ?
 
Structure will be something like this:
 
public void processReport()
    {
       XX_myContract contract;
       
        contract = this.parmDataContract() as XX_myContract ;
       .
       .
       this.updateTmp();
   }
 
 
void updateTmp()
    {
         < I want to access or use the same "contract" variable here >
    }
 
 
 
Thanks.
 
 
  • Layan Jwei Profile Picture
    Layan Jwei 4,349 Super User on at
    Variable scope
    Hi,
     
    Is your question answered? If yes, then please verify the answers that helped
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 4,349 Super User on at
    Variable scope
    Hi CU,

    Why not use this.ParmDataContract() and call it again inside updateTmp method?

    or if you insist to use the same variable, then you can pass the contract variable to the updateTmp() method
    public void processReport()
    {
        XX_myContract contract;
           
        contract = this.parmDataContract() as XX_myContract ;
    
        this.updateTmp(contract);
    }
    
    
    void updateTmp(XX_myContract _contract)
    {
        // use _contract here
    }


    OR a third way maybe is to define contract variable globally:
    class RDP
    {
       XX_myContract contract;
    
       public void processReport()
       {    
           contract = this.parmDataContract() as XX_myContract ;
    
           this.updateTmp();
       }
    
    
       void updateTmp()
       {
           // use contract directly (assuming it's filled inside processReport) you can make some defensive coding
       }
    }

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 285,356 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,435 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans