You need to sign in to do that
Don't have an account?
![EQ Admin EQ Admin](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Need help to generate json pattern like below:
"InvoiceSourceSystem": "APTTUS",
"ExternalCompanyId": "APTTUS",
"FromDate": "2019-08-01",
"ToDate": "2019-08-03",
"TotalNumberOfInvoices": "109",
"Invoices": [
{
"HeaderKey": "1",
"AddOnly": "",
"AutoComplete": "Y",
"CustomerInvoiceID": "378958d7-d4af-e911-bcd0-00155d69e630",
"Submit": "Y",
"LockedinWorkday": "N",
"Company": "5103",
"Currency": "USD",
"Customer": "EQ145959",
"SoldToCustomer": "",
"BillToContact": "",
"BillToAddress": "",
"RowID": "",
"InvoiceNumber": "INV-000000003531",
"InvoiceDate": "2019-07-26",
"AccountingDate": "",
"FromDate": "",
"ToDate": "",
"DueDateOverride": "2019-08-25",
"ControlTotalAmount": "",
"PaymentTerms": "",
"PaymentType": "",
"AmountDue": "20663.82",
"IncludeCustomerWorktags": "",
"Memo": "",
"InvoiceLineItem": [
{
"HeaderKey": "1",
"LineKey": "1",
"CustomerInvoiceLine": "",
"CustomerInvoiceLineReferenceID": "INV-000000003531-1",
"LineOrder": "",
"IntercompanyAffiliate": "",
"SalesItemIDType": "",
"SalesItemIDValue": "",
"RevenueCategory": "RC900",
"LineItemDescription": "Invoice total",
"ShipToCustomerIDType": "",
"ShipToCustomerIDValue": "",
"ShipToAddressIDType": "",
"ShipToAddressIDValue": "",
"Quantity": 1,
"UnitofMeasure": "EA",
"UnitCost": "",
"ExtendedAmount": "20663.82",
"TransactionDate": "",
"FromDate": "",
"ToDate": "",
"DeferredRevenue": "",
"RevenueRecognitionScheduleTemplate": "",
"Memo": "",
"AnalyticalAmount": "",
"Product": "",
"IssueNumber": "",
"IssueNumberType": "",
"CostCenter": ""
},
My Code:
/*
*/
@RestResource(urlMapping='/WorkdayIntegration/')
global class APTS_InvoiceDetailsWS
{
@HttpPost
global static List<APTS_WorkdayIntegrationWrapper> getInvoiceDetails()
{
String JsonString;
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(RestContext.request.requestBody.toString());
Date startDate=Date.valueOf((String)params.get('StartDate'));
Date endDate=Date.valueOf((String)params.get('EndDate'));
String approved='Approved';
String query='Select id,Name,EQ_InvoiceApprovedDate__c,Apttus_billing__status__c,CurrencyIsoCode,Apttus_Billing__ShipToAccountId__r.EQ_ClientRef__c,Apttus_Billing__ShipToAccountId__r.EQ_ShippingState__c,Apttus_Billing__InvoiceDate__c,EQ_DueDateCustom__c,EQ_TotalTaxAmount__c from Apttus_Billing__Invoice__c where EQ_InvoiceApprovedDate__c>=:startDate and EQ_InvoiceApprovedDate__c<=:endDate and EQ_TotalInvoiceAmount__c > 0 and Apttus_billing__status__c=:approved';
List<Apttus_Billing__Invoice__c> invoiceObjectList1=Database.query(query);
List<APTS_WorkdayIntegrationWrapper> lstInvoiceHistory = new List<APTS_WorkdayIntegrationWrapper>();
Integer count=0;
for(Apttus_Billing__Invoice__c invoice:invoiceObjectList1)
{
count=count+1;
APTS_WorkdayIntegrationWrapper invoiceWrapper=new APTS_WorkdayIntegrationWrapper();
invoiceWrapper.InvoiceSourceSystem='APTTUS';
invoiceWrapper.ExternalCompanyId='APTTUS';
invoiceWrapper.FromDate=(String)params.get('StartDate');
invoiceWrapper.ToDate=(String)params.get('EndDate');
invoiceWrapper.TotalNumberOfInvoices=count;
invoiceWrapper.HeaderKey=null;
invoiceWrapper.AddOnly='';
invoiceWrapper.AutoComplete='Y';
invoiceWrapper.CustomerInvoiceID=invoice.id;
invoiceWrapper.Submit='Y';
invoiceWrapper.LockedinWorkday='N';
invoiceWrapper.Company='5103';
invoiceWrapper.CurrencyISOCode=invoice.CurrencyIsoCode;
invoiceWrapper.Customer=''; /* need to confirm accountr*/
invoiceWrapper.SoldToCustomer='';
invoiceWrapper.BillToContact='';
invoiceWrapper.BillToAddress='';
invoiceWrapper.RowID='';
invoiceWrapper.InvoiceNumber=invoice.Name;
invoiceWrapper.InvoiceDate=invoice.Apttus_Billing__InvoiceDate__c;
invoiceWrapper.AccountingDate='';
//invoiceWrapper.FromDate
//invoiceWrapper.ToDate
invoiceWrapper.DueDateOverride='';
invoiceWrapper.ControlTotalAmount=invoice.EQ_TotalTaxAmount__c;
invoiceWrapper.PaymentTerms='';
invoiceWrapper.PaymentType='';
invoiceWrapper.AmountDue='';
invoiceWrapper.IncludeCustomerWorktags='';
invoiceWrapper.Memo='';
lstInvoiceHistory.add(invoiceWrapper);
}
return lstInvoiceHistory;
}
global class APTS_WorkdayIntegrationWrapper
{
public String InvoiceSourceSystem;
public String ExternalCompanyId;
public integer TotalNumberOfInvoices;
public DecimAL HeaderKey;
public String AddOnly;
public String AutoComplete;
public String CustomerInvoiceID;
public String Submit;
public String LockedinWorkday;
// public List<Invoices> Invoices;
public String Company;
public String CurrencyISOCode;
public String Customer;
public String SoldToCustomer;
public String BillToContact;
public String BillToAddress;
public String RowID;
public String InvoiceNumber;
public DateTime InvoiceDate;
public String AccountingDate;
public String FromDate;
public String ToDate;
public String DueDateOverride;
public Decimal ControlTotalAmount;
public String PaymentTerms;
public String PaymentType;
public String AmountDue;
public String IncludeCustomerWorktags;
public String Memo;
}
public class fromJSON
{
public String Parm1; //Value1
public String Parm2; //Value2
}
}
"ExternalCompanyId": "APTTUS",
"FromDate": "2019-08-01",
"ToDate": "2019-08-03",
"TotalNumberOfInvoices": "109",
"Invoices": [
{
"HeaderKey": "1",
"AddOnly": "",
"AutoComplete": "Y",
"CustomerInvoiceID": "378958d7-d4af-e911-bcd0-00155d69e630",
"Submit": "Y",
"LockedinWorkday": "N",
"Company": "5103",
"Currency": "USD",
"Customer": "EQ145959",
"SoldToCustomer": "",
"BillToContact": "",
"BillToAddress": "",
"RowID": "",
"InvoiceNumber": "INV-000000003531",
"InvoiceDate": "2019-07-26",
"AccountingDate": "",
"FromDate": "",
"ToDate": "",
"DueDateOverride": "2019-08-25",
"ControlTotalAmount": "",
"PaymentTerms": "",
"PaymentType": "",
"AmountDue": "20663.82",
"IncludeCustomerWorktags": "",
"Memo": "",
"InvoiceLineItem": [
{
"HeaderKey": "1",
"LineKey": "1",
"CustomerInvoiceLine": "",
"CustomerInvoiceLineReferenceID": "INV-000000003531-1",
"LineOrder": "",
"IntercompanyAffiliate": "",
"SalesItemIDType": "",
"SalesItemIDValue": "",
"RevenueCategory": "RC900",
"LineItemDescription": "Invoice total",
"ShipToCustomerIDType": "",
"ShipToCustomerIDValue": "",
"ShipToAddressIDType": "",
"ShipToAddressIDValue": "",
"Quantity": 1,
"UnitofMeasure": "EA",
"UnitCost": "",
"ExtendedAmount": "20663.82",
"TransactionDate": "",
"FromDate": "",
"ToDate": "",
"DeferredRevenue": "",
"RevenueRecognitionScheduleTemplate": "",
"Memo": "",
"AnalyticalAmount": "",
"Product": "",
"IssueNumber": "",
"IssueNumberType": "",
"CostCenter": ""
},
My Code:
/*
*/
@RestResource(urlMapping='/WorkdayIntegration/')
global class APTS_InvoiceDetailsWS
{
@HttpPost
global static List<APTS_WorkdayIntegrationWrapper> getInvoiceDetails()
{
String JsonString;
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(RestContext.request.requestBody.toString());
Date startDate=Date.valueOf((String)params.get('StartDate'));
Date endDate=Date.valueOf((String)params.get('EndDate'));
String approved='Approved';
String query='Select id,Name,EQ_InvoiceApprovedDate__c,Apttus_billing__status__c,CurrencyIsoCode,Apttus_Billing__ShipToAccountId__r.EQ_ClientRef__c,Apttus_Billing__ShipToAccountId__r.EQ_ShippingState__c,Apttus_Billing__InvoiceDate__c,EQ_DueDateCustom__c,EQ_TotalTaxAmount__c from Apttus_Billing__Invoice__c where EQ_InvoiceApprovedDate__c>=:startDate and EQ_InvoiceApprovedDate__c<=:endDate and EQ_TotalInvoiceAmount__c > 0 and Apttus_billing__status__c=:approved';
List<Apttus_Billing__Invoice__c> invoiceObjectList1=Database.query(query);
List<APTS_WorkdayIntegrationWrapper> lstInvoiceHistory = new List<APTS_WorkdayIntegrationWrapper>();
Integer count=0;
for(Apttus_Billing__Invoice__c invoice:invoiceObjectList1)
{
count=count+1;
APTS_WorkdayIntegrationWrapper invoiceWrapper=new APTS_WorkdayIntegrationWrapper();
invoiceWrapper.InvoiceSourceSystem='APTTUS';
invoiceWrapper.ExternalCompanyId='APTTUS';
invoiceWrapper.FromDate=(String)params.get('StartDate');
invoiceWrapper.ToDate=(String)params.get('EndDate');
invoiceWrapper.TotalNumberOfInvoices=count;
invoiceWrapper.HeaderKey=null;
invoiceWrapper.AddOnly='';
invoiceWrapper.AutoComplete='Y';
invoiceWrapper.CustomerInvoiceID=invoice.id;
invoiceWrapper.Submit='Y';
invoiceWrapper.LockedinWorkday='N';
invoiceWrapper.Company='5103';
invoiceWrapper.CurrencyISOCode=invoice.CurrencyIsoCode;
invoiceWrapper.Customer=''; /* need to confirm accountr*/
invoiceWrapper.SoldToCustomer='';
invoiceWrapper.BillToContact='';
invoiceWrapper.BillToAddress='';
invoiceWrapper.RowID='';
invoiceWrapper.InvoiceNumber=invoice.Name;
invoiceWrapper.InvoiceDate=invoice.Apttus_Billing__InvoiceDate__c;
invoiceWrapper.AccountingDate='';
//invoiceWrapper.FromDate
//invoiceWrapper.ToDate
invoiceWrapper.DueDateOverride='';
invoiceWrapper.ControlTotalAmount=invoice.EQ_TotalTaxAmount__c;
invoiceWrapper.PaymentTerms='';
invoiceWrapper.PaymentType='';
invoiceWrapper.AmountDue='';
invoiceWrapper.IncludeCustomerWorktags='';
invoiceWrapper.Memo='';
lstInvoiceHistory.add(invoiceWrapper);
}
return lstInvoiceHistory;
}
global class APTS_WorkdayIntegrationWrapper
{
public String InvoiceSourceSystem;
public String ExternalCompanyId;
public integer TotalNumberOfInvoices;
public DecimAL HeaderKey;
public String AddOnly;
public String AutoComplete;
public String CustomerInvoiceID;
public String Submit;
public String LockedinWorkday;
// public List<Invoices> Invoices;
public String Company;
public String CurrencyISOCode;
public String Customer;
public String SoldToCustomer;
public String BillToContact;
public String BillToAddress;
public String RowID;
public String InvoiceNumber;
public DateTime InvoiceDate;
public String AccountingDate;
public String FromDate;
public String ToDate;
public String DueDateOverride;
public Decimal ControlTotalAmount;
public String PaymentTerms;
public String PaymentType;
public String AmountDue;
public String IncludeCustomerWorktags;
public String Memo;
}
public class fromJSON
{
public String Parm1; //Value1
public String Parm2; //Value2
}
}
![EQ Admin EQ Admin](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Please help me how can i achieve this. I am able to get the json but not in this format.