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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

How to Run Batch Job Through the Menu button?

(0) ShareShare
ReportReport
Posted on by 932

Hi,

I add this code in the clicked method of button  :  

treeItemIdx = MenusTree.getFirstSelected();
idx = treeItemIdx != 0 ? treeItemIdx : EUKMatrixRoleHelper::getIdByTreeItemData(MenusTree,buildNavigationTree.currentTreeItem().data());
formTreeItem = MenusTree.getItem(idx);
securityMenus = EUKSecurityMenus::findRecId(formTreeItem.data());
treeNode = TreeNode::findNode(securityMenus.path());

formRoot=element.getFormTreeItem(treeItemIdx);
if (formRoot)
{
    securityMenusParent=EUKSecurityMenus::findRecId(formRoot.data());
}

pathRoot = securityMenusParent.Path();
if (element.isMenuItemNode(treeNode))
{               
    actionTreeUnitValuation.addModificationMain(RadioButtonSecurityLevel.selection());
    modify = true;
}
else
{          
    actionTreeMassValuation.addModificationMain(RadioButtonSecurityLevel.selection());
    modify = true;
}

Now I want to execute this code in batch job ,

How can I do this?

I have the same question (0)
  • Martin Dráb Profile Picture
    239,880 Most Valuable Professional on at

    You can't execute this code in a batch job, because it refers to form controls. You could collect input data from the form, put it into a data contract and pass this data contract to batch job for later processing.

    Nevertheless I'm not sure if it makes sense in this particular case. What is actionTreeUnitValuation.addModificationMain()? Is it something that can be executed in a batch at all?

  • nmaenpaa Profile Picture
    101,172 Moderator on at

    What does this code do? And why would you want to run it as a batch job?

    You can use SysOperation or RunBaseBatch framework to develop a batch job.

    However your batch job will not have access to this form, or any elements in it. So your code would need to be restructured in a way that you first read all the relevant selections and details from the form, and then send those pieces of information into your batch class.

    But let's start by understanding what your code does, and why it should run as a batch.

  • BASMA Profile Picture
    932 on at

    Hi Martin,

    actionTreeUnitValuation.addModificationMain()  :

    it is a process that allows to insert information into a table following conditions.

    Have you any example how to use data contract and pass it to batch job?

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

    If you are doing a simple (= quick-ish) insert, based on the user's input in the form, I don't see why it should run as a batch job. So could you let us know why you decided that it should run in a batch job?

    But if you want to do it in a batch job, then your batch job must have parameters / data members that the job can use to determine what to insert into which table(s).

  • BASMA Profile Picture
    932 on at

    I decided to use batch job , because the code takes a long time to complete

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

    Could you share your code?

    You told us that "it is a process that allows to insert information into a table following conditions." but that description is very generic. It would really help if we could understand what this form does, what the button click does, and what is the business process behind it.

    Anyway if you need a batch, you have now some input from us, and should be able to proceed.

  • BASMA Profile Picture
    932 on at

    the most important doesn't  the method "AddModificationMain"  but this part of code  : 

    treeItemIdx = MenusTree.getFirstSelected();
    idx = treeItemIdx != 0 ? treeItemIdx : EUKMatrixRoleHelper::getIdByTreeItemData(MenusTree,buildNavigationTree.currentTreeItem().data());
    formTreeItem = MenusTree.getItem(idx);
    securityMenus = EUKSecurityMenus::findRecId(formTreeItem.data());
    treeNode = TreeNode::findNode(securityMenus.path());
    
    formRoot=element.getFormTreeItem(treeItemIdx);
    if (formRoot)
    {
        securityMenusParent=EUKSecurityMenus::findRecId(formRoot.data());
    }
    
    pathRoot = securityMenusParent.Path();

    this code

    how Can I pass args from this form to class that extends runBaseBatch?

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

    Could you please tell us what line of code (in the code that you shared) is the one that takes a lot of time to execute? Please let us know. You need to know it before you can decide how to move forward.

    If it's line 2, you can't move it to batch since it's completely depending on your form controls.

  • nmaenpaa Profile Picture
    101,172 Moderator on at

    Also, about passing args from a form to RunBaseBatch, you can find a lot of info by typing that into a web search: www.google.com/search

    But as we have mentioned, you should first provide us more details. Let's evaluate all the details first before deciding the direction that should be taken. Otherwise you might spend your time on things that will not solve your actual problem.

  • BASMA Profile Picture
    932 on at

    Yes , I want to pass the values with red color

    treeItemIdx = MenusTree.getFirstSelected();
    idx = treeItemIdx != 0 ? treeItemIdx : EUKMatrixRoleHelper::getIdByTreeItemData(MenusTree,buildNavigationTree.currentTreeItem().data());
    formTreeItem = MenusTree.getItem(idx);
    securityMenus = EUKSecurityMenus::findRecId(formTreeItem.data());
    treeNode = TreeNode::findNode(securityMenus.path());

    formRoot=element.getFormTreeItem(treeItemIdx);
    if (formRoot)
    {
    securityMenusParent=EUKSecurityMenus::findRecId(formRoot.data());
    }

    PathRoot = securityMenusParent.Path();
    if (element.isMenuItemNode(treeNode))
    {
    actionTreeUnitValuation.addModificationMain(RadioButtonSecurityLevel.selection());
    modify = true;
    }

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Subra Profile Picture

Subra 500

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 462 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 461 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans