Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Send Journal details via API

Posted on by 59
Hello guys, I am trying to send information from my custom tables through an API as JSON. so far I have been able to just send a part of the data, lets say I have 3 lines in my journal, the code sends the header alongside just 2 lines, another issue is the information is getting to the end point as a string. I need it to come as json. Any pointers will be helpful. 
 
This is my code: 
internal final class TestButtonClass{    [FormControlEventHandler(formControlStr(MOVendorPayment, TestButton), FormControlEventType::Clicked)]    public static void TestButton_OnClicked(FormControl sender, FormControlEventArgs e)    {        // Get the current record from the header data source        FormDataSource headerDS = sender.formRun().dataSource(formDataSourceStr(MOVendorPayment, MOVendorPaymentHeaderTable));        FormDataSource linesDS = sender.formRun().dataSource(formDataSourceStr(MOVendorPayment, MOVendorPaymentLinesTable));        if (headerDS && linesDS)        {            // Get the header record            MOVendorPaymentHeaderTable headerRecord = headerDS.cursor();            MOVendorPaymentLinesTable linesRecord;            // Create a string to hold line data            str linesData = //;            int numLines = 0;            // Loop through all lines associated with the header            while (linesDS.next())            {                linesRecord = linesDS.cursor();                // Add each line's data to the string                str lineData = strFmt(                    /{///Currency///:///%1///,///Amount///:///%2///,///DateTrans///:///%3///,///Description///:///%4///,///CountryCode///:///%5///,///HasIntermediary///:%6,///IntermediaryAccountNumber///:///%7///,///VendorName///:///%8///,///RoutingNumber///:///%9///,///SwiftCode///:///%10///,///IntermediaryBankAddress///:///%11///,///IntermediaryBankName///:///%12///,///IntermediarySortCode///:///%13///,///IntermediarySwiftCode///:///%14///,///PaymentReference///:///%15///}/,                    linesRecord.Currency,                    linesRecord.Amount,                    linesRecord.DateTrans,                    linesRecord.Description,                    linesRecord.CountryCode,                    linesRecord.HasIntermediary,                    linesRecord.IntermediaryAccountNumber,                    linesRecord.VendorName,                    linesRecord.RoutingNumber,                    linesRecord.SwiftCode,                    linesRecord.IntermediaryBankAddress,                    linesRecord.IntermediaryBankName,                    linesRecord.IntermediarySortCode,                    linesRecord.IntermediarySwiftCode,                    linesRecord.PaymentReference                );                if (numLines > 0)                {                    linesData += /,/;                }                linesData += lineData;                // Increment the line count                numLines++;            }            // Combine header and lines data into a single JSON request            str requestContent = strFmt('{/JournalBatchNumber/:/%1/,/Description/:/%2/,/NumOfLines/:/%3/,/PaymentGateway/:/%4/,/LinesData/:[%5]}',                headerRecord.JournalBatchNumber,                headerRecord.Description,                headerRecord.NumofLines,                headerRecord.PaymentGateway,                linesData);            // Log the combined request            info(strFmt(/Combined Request: %1/, requestContent));            // Make the API call with the combined requestContent            var response = VendPaymentAPI.VendPayment.Helper::PostActivityAsync(requestContent, https://sfqa.mainone.net/salesforce/api/eqform//);            info(/Payment Instructions sent to Bank, Pending Approval, Testbutton/);        }        else        {            error(/No header or lines record selected./);        }    }}
 

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans