Skip to main content

Notifications

Announcements

No record found.

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
  • Layan Jwei Profile Picture
    Layan Jwei 7,264 Super User 2024 Season 2 on at
    calling api from postman that creating batch job class x++
    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
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 10,611 Super User 2024 Season 2 on at
    calling api from postman that creating batch job class x++
    Hi @Menna,
     
    Try to run the class in asynchronous mode 
    Global::runAsync(...);
    Best regards,
    Mohamed Amine MAHMOUDI
  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    calling api from postman that creating batch job class x++
    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
    Mohamed Amine Mahmoudi 10,611 Super User 2024 Season 2 on at
    calling api from postman that creating batch job class x++
    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
    Menna Allah Ahmed 163 on at
    calling api from postman that creating batch job class x++
    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 .
     
     
     
  • Waed Ayyad Profile Picture
    Waed Ayyad 6,556 Super User 2024 Season 2 on at
    calling api from postman that creating batch job class x++
    Hi,
     
    Did you try to call it from runnable class? Also, can share what you got when you called it through the postman?
     
  • Layan Jwei Profile Picture
    Layan Jwei 7,264 Super User 2024 Season 2 on at
    calling api from postman that creating batch job class x++
    Hi,
     
    Can you please explain what do u mean by "it doesn't work" what's ur issue exactly?
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 10,611 Super User 2024 Season 2 on at
    calling api from postman that creating batch job class x++
    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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans