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./); } }}