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

Notifications

Announcements

Community site session details

Community site session details

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

calling api from postman that creating batch job class x++

(1) ShareShare
ReportReport
Posted on by 163
I want to call api that creating batch job class and executing it . This class will take all service orders from CRM and insert it in FO .
I tried to do that by creating service and service group and two classes , one is runnable class get token , request , response and insert data (it works well when I create batch job manually and data inserted)
other class is creating batch job and execute it but it doesn't work 
This class that I called in service 
 
class InsertSO_FromCRM 
{
    public void InsertWO_FO()
    {   
                BatchHeader                                           batHeader;
                BatchInfo                                           batInfo;
                WO_SO_CRM                                          WO_SO_CRM ;
                str sParmCaption = /CFM Insert work orders Batch 2/;
                WO_SO_CRM  = new WO_SO_CRM();
                batInfo = WO_SO_CRM .batchInfo();
                batInfo.parmCaption('CFM Insert work orders Batch 2');
                batInfo.parmGroupId(//);
                batHeader = BatchHeader::construct();
                batHeader.addTask(WO_SO_CRM);
                batHeader.save();
                info(strFmt(/%1 batch has been scheduled./, sParmCaption));
    }
}
 
 
So what 's missing or what should I do to call service 
I called it like 
service name : InsertSO_FromCRM
service group name : TestJSONServiceGroup
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,765 Super User 2026 Season 1 on at
    Hi @Menna,
     
    Try this :
    class InsertSO_FromCRM 
    {
        public void InsertWO_FO()
        {         
            BatchHeader                 header;
            SysRecurrenceData           sysRecurrenceData;
            Batch                       batch;
            BatchJob                    batchJob;
            WO_SO_CRM                   WO_SO_CRM; // Class extends RunBaseBatch
            BatchInfo                   processBatchInfo;
            BatchRetries                noOfRetriesOnFailure = 4;
            ;
     
            // Setup the RunBaseBatch Job
            header = BatchHeader::construct();
            WO_SO_CRM = new WO_SO_CRM();
            processBatchInfo = WO_SO_CRM.batchInfo();
            processBatchInfo.parmRetriesOnFailure(noOfRetriesOnFailure);
            processBatchInfo.parmCaption("My batch 2"); // Description Batch Job
            processBatchInfo.parmGroupId(''); // Batch Gorup
            processBatchInfo.parmBatchExecute(NoYes::Yes);
            header.addTask(WO_SO_CRM);
     
            // Set the recurrence data
            sysRecurrenceData = SysRecurrence::defaultRecurrence();
            SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData, DateTimeUtil::addSeconds(DateTimeUtil::utcNow(), 20)); // Set range of recurrence
            SysRecurrence::setRecurrenceNoEnd(sysRecurrenceData);
            SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::Minute); // Set reccurence pattern
            header.parmRecurrenceData(sysRecurrenceData);
            // Set the batch alert configurations
            header.parmAlerts(NoYes::Yes, NoYes::Yes, NoYes::Yes, NoYes::Yes, NoYes::Yes);
            header.save();
        }
    }
    Best regards,
    Mohamed Amine MAHMOUDI
  • Layan Jwei Profile Picture
    8,165 Super User 2026 Season 1 on at
    Hi,
     
    Can you please explain what do u mean by "it doesn't work" what's ur issue exactly?
  • Waed Ayyad Profile Picture
    9,061 Super User 2026 Season 1 on at
    Hi,
     
    Did you try to call it from runnable class? Also, can share what you got when you called it through the postman?
     
  • Menna Allah Ahmed Profile Picture
    163 on at
    Hi @Mohamed I tried your solution but still doesn't work I called api from postman and it is successful but still batch job didn't create .
    Hi @Waed , @Layan My issue that I called api from postman but batch doesn't  created but when I put my code in runnable class it works well .
     
     
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,765 Super User 2026 Season 1 on at
    Hi @Menna,
    I suggest you follow these steps :
    - Create a runnable class with the code of batch job (for e.g. CreateBatchJob)
    - Create a ActionMenuItem and assigned to runnable class (CreateBatchJob)
    - Call this menu item from your class
    MenuFunction    menuFunction;
    Args            args = new Args();
    
    menuFunction = new MenuFunction(menuItemActionStr(CreateBatchJob), MenuItemType::Action);
    menuFunction.run(args);
    Best regards,
    Mohamed Amine MAHMOUDI
  • Menna Allah Ahmed Profile Picture
    163 on at
    Hi Mohamed , 
    thanks for helping me but still doesn't work I created a new runnable class with code and called menu item in another class but still I have the same problem when I called this api from postman batch job doesn't create .
    This is runnable class 
    internal final class InsertSO_Runnable
    {
        /// <summary>
        /// Class entry point. The system will call this method when a designated menu 
        /// is selected or when execution starts and this class is set as the startup class.
        /// </summary>
        /// <param name = "_args">The specified arguments.</param>
        public static void main(Args _args)
        {
            BatchHeader                                           batHeader;
            BatchInfo                                           batInfo;
            WO_SO_CRM                                          WO_SO_CRM ;
            str sParmCaption = "CFM Insert work orders Batch 3";
            WO_SO_CRM  = new WO_SO_CRM();
            batInfo = WO_SO_CRM .batchInfo();
            batInfo.parmCaption('CFM Insert work orders Batch 3');
            batInfo.parmGroupId("");
            batHeader = BatchHeader::construct();
            batHeader.addTask(WO_SO_CRM);
            batHeader.save();
            info(strFmt("%1 batch has been scheduled.", sParmCaption));
        }
    }
     
    this is class that I called in service
    class InsertSO_FromCRM 
    {
        public void InsertWO_FO()
        {
            MenuFunction    menuFunction;
            Args            args = new Args();
            menuFunction = new MenuFunction(menuItemActionStr(CreateBatchJob_InsertedSO), MenuItemType::Action);
            menuFunction.run(args);

        }
    }
     
    this is my api that I called from postman
    DEVURL/api/services/TestJSONServiceGroup/InsertSO_FromCRM/InsertWO_FO
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,765 Super User 2026 Season 1 on at
    Hi @Menna,
     
    Try to run the class in asynchronous mode 
    Global::runAsync(...);
    Best regards,
    Mohamed Amine MAHMOUDI
  • Layan Jwei Profile Picture
    8,165 Super User 2026 Season 1 on at
    Hi Menna,

    Are you getting any errors from postman?

    did you try to debug the service class when calling the api from postman to see what goes wrongly? compare the values of the buffers when you create it manually and when you create via postman to see what's wrong

    Thanks,
    Layan Jweihan

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 332 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 238 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans