web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to pass args from class to main method of class that extends runBaseBatch?

(0) ShareShare
ReportReport
Posted on by

Hi , 

I have this dialog : 

pastedimage1600163955403v1.png              

public void run(Args _args)
{
    
    dialog.run();
        if (dialog.closedOk())
        {
            BatchClass::main(_args);
        }
}

When I click on button "Ok" I want to pass args in the 2end class that extends runBase Batch : 

When I click on button Ok , this form will be opening  : 

pastedimage1600164201691v2.png        

public static void main(Args _args)
{
    BatchClass    batchClass;
   
    batchClass = BatchClass::construct();
    batchClass.caption();
    if(batchClass.prompt())
   {
        RoleVersion = _args.record(); //When I run this code on batch the value of 
       // Role version was nul
        RoleVersion.run();
   }
 }

I don't understand why  args is null when I run this class in batch.

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Main method of the batch class is run only when you launch the batch dialog. When the actual batch process executes it, this method is not run.

    So, you need to add all variables that the batch needs in the classDeclaration and [tag:CurrentList] of your batch class. And add a parm method which you can use to pass the variable from main method to the actual class instance after instantiating the class.

    I think you can only use simple data types, not table buffers.

  • Community Member Profile Picture
    on at

    Hi, 

    I dont understand  what you means   :  " And add a parm method which you can use to pass the variable from main method to the actual class instance after instantiating the class."

  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    You need to pass a value to an object, like this:

    batchClass = BatchClass::construct();
    batch.parmMyValue("whatever");

    To be able to do that, you must define the method first (if it doesn't already exist).

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Basma,

    The main method is a static method where you are instantiating the class which runs the batch process. If you want to pass some values into this class, you need to create a global variable in the class. Then you write a parm method which gets/sets this variable.

    For an example, you can take a look at Tutorial_RunBaseBatchForm class. 

    There is a variable declared - "custAccount". The variable is also included in the CurrentList macro

    pastedimage1600168447132v1.png

    In the same class, you can check the method parmCustAccount, which can be used for setting the value for custAccount and getting its value as well.

    pastedimage1600168527594v2.png

    Do, from the main method you could write something like -

    batchClass.parmCustAccount("00001");

  • Community Member Profile Picture
    on at

    Thanks ,

    I create method that return the values which are packed : 

    public class RoleBatch extends RunBaseBatch
    {
       
        
        int64          versionRecId; 
        str            _roleNameGlb;
        int64          roleRecId;
        RoleVersion    _matrixRoleVersion;
        #define.CurrentVersion(1)
        #define.Version1(1)
        #localmacro.CurrentList
              versionRecId,
             _roleNameGlb,
              roleRecId
        #endmacro
    }

    public  void getValues(str _roleName , RoleVersion _roleVersion,Role _eukRole )
    {
         
        _roleNameGlb = _roleName;
        select * from _matrixRoleVersion where _matrixRoleVersion.RecId  == _roleVersion.RecId;
        versionRecId = _matrixRoleVersion.RecId;
        select firstonly RoleGlb where RoleGlb.RecId== _eukRole.RecId;
        roleRecId = RoleGlb.RecId;
    }

    in the main method of class that extends runbaseBatch  :  

    public static void main(Args _args)
    {
       RoleBatch               generateSecurityRole;
        RoleVersion             eukMatrixRoleVersion;
        Role                   eukRole;
        RoleCreateRole         roleCreateRole;
       
        MatrixRole                   MatrixRole = null;
        Args                            argsGenerationFromMatrix;
        str                              roleName;
        str CompanyId;
    
        utcDateTime                     dateTime = DateTimeUtil::utcNow();
        ;
        CompanyId = CompanyInfo::Find().DataArea;
        generateSecurityRole = RoleBatch::construct();
        generateSecurityRole.caption();
        if(generateSecurityRole.prompt())
       {
            eukMatrixRoleVersion = _args.record();
            eukMatrixRoleCreateRole = MatrixRoleCreateRole::constructFromArgs(_args);
            eukMatrixRole = eukMatrixRoleCreateRole.eukMatrixRole();
            select firstonly eukRole where eukRole.RelatedMatrix == eukMatrixRole.MatrixID;
            if (eukRole)
            {
                roleName = eukRole.Name;
            }
            else
            {
                roleName = CompanyId "-"  eukMatrixRole.MatrixName;
    
            }
            info(roleName);
            info(int642str(eukMatrixRoleVersion.RecId));
            generateSecurityRole.getValues(roleName,eukMatrixRoleVersion,eukRole);
            generateSecurityRole.run();
    
        }
    
    
    }

    I use your suggestion in the main method of class that  extends runBaseBatch or the first class?

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Basma,

    I thought you had only one class. It should be in the main of the class extending RunBaseBatch.

    Not sure why you have another class though.

  • Community Member Profile Picture
    on at

    I have the first class from it I want to get values  :

    class MatrixRoleCreateRoleDialog
    {
    //this is the first class from it I want to get values 
    }

    public void run(Args _args)
    {
       dialog.run();
       if (dialog.closedOk())
        {
              //I want to pass values to class extending runbaseBatch
              RoleBatch::main(_args);
        }
      }

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    By the way, I think you were trying to implement similar functionality using SysOperation about 1-2 weeks ago, but using a different username Just "Basma" instead of "Basma WED". Any particular reason why you abandoned that code and are now trying to implement it via RunBaseBatch?

    I think we were discussing the exact same question - how to pass some value from caller class to your batch. And as far as I remember we demonstrated to you how to do it. But now you have changed the framework and are dealing with the same problem again.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    First of all, you should try to split your problem in small parts. Then solve one part at a time. Also jumping between different frameworks (SysOperation and RunBaseBatch) might not be productive, instead I recommend trying to learn to understand one of them first. Once you understand the concepts and can effortlessly develop functionalities using one of the frameworks, it should be easy to learn the other. But if you have difficulties with understanding the fundamentals, you are just making your life more difficult if you jump between them.

    Your first part is passing values from class to another. This has nothing to do with batches!

    I thought you already managed to pass values from one class to another, and your only problem was to use them in batch. But apparently even your first part is not working yet. So please forget the batch for now and only resume once you have completed the first part.

    For the first part, here are the required steps:

    Put this in the first class:

    public void run(Args _args)
    {
       dialog.run();
       if (dialog.closedOk())
        {
              Args args = new Args();
              args.caller(this);
              //I want to pass values to class extending runbaseBatch
              RoleBatch::main(args);
        }
      }

    By the way, I don't know what is in "_args" parameter of the run method, and I don't know if you have something valuable there. I assume that you don't have anything there that is needed in the batch class, so I'm instantiating a new Args object and passing "this" (=pointer to the current class) into it.

    In your second class (the batch class) you can access any methods of the caller class from the main method of your batch class:

    public static void main(Args _args)
    {
         MyFirstClass myFirstClass = _args.caller();
         // Now you can call any methods of myFirstClass to fetch values from it
         string myString = myFirstClass.getMyString();
    }

  • Community Member Profile Picture
    on at

    Hi,

    we are two colleagues working on the same task, she tried the sysoperation framework, and I tried with runBaseBatch.

    But we are both stuck with the batch.

    For  information , If run my class without batch I haven't any problem.

    But when I use the batch , I can't get any values

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans