You can use createDirectCreditMemosAsync API to create credit memos for an invoice with large number of invoice line items. This API is an asynchronous API and it submits batch jobs to create direct credit memos. You can use this API to create credit memos for a large number of invoices or invoices with a large number of invoice line items.
|createDirectCreditMemosAsync||static List createDirectCreditMemosAsync(List creditMemoInputs)|
This API is used to create credit memos for an invoice. It accepts a Set of Account IDs, invoiceDate, and targetDateTime as input parameters. For each DirectCreditMemoInput, a credit memo is created in the Draft Status. You can auto-approve a credit memo line item and auto-apply it to an invoice. If you have a Tax Callback registered, this API also calculates Tax and creates Tax breakups for a credit memo line item.
Request - DirectCreditMemoInput
The Id of the approved Invoice the credit will be drawn from.
|reasonCode||String||Yes||The reason for creating the Credit Memo. Must be null or a valid pick-list|
value for the Reason Code field declared of the Credit Memo object.
If you set isFullCredit as true, the entire available credit amount of all the invoice line items is set as the credit amount.
If you set the value as false, credit memo amount is calculated based on the values you provide in creditMemoLineItemInputs field.
By default, it is set as false.
The list of inputs for each Credit Memo Line Item to create.
This parameter is ignored if you set isFullCredit as True.
|autoApprove||Boolean||No||If true the Credit Memo will be transitioned to Approved otherwise the Credit Memo will be created with a status of Draft. A value of null will|
be considered as false.
|autoApplyCreditMemo||Boolean||No||This flag is only relevant when the Auto Approve option is true. If both options are true the newly created direct Credit Memo will be applied|
to the Invoice, the credit was drawn from. A value of null will be considered as false.
|TemplateId||ID||No||The Id of the Credit Memo template to use when creating the Credit Memo attachment. This parameter is optional and can be null.|
|calculateTax||Boolean||Yes||If this flag is true Tax will be calculated for a non tax-exempt Asset. If it is set to false, no tax will be calculated.|
Ensure that you provide value for either isFullCredit or creditMemoLineItemInputs parameters. If you leave both the fields as null, the API returns an error.
Request - CreditMemoLineItemInput
|invoiceLineItemId||ID||Yes||The Id of the affiliate Invoice Line Item. It must be a child of the specified Invoice.|
|creditAmount||Decimal||Yes||The amount of credit to draw from the corresponding Invoice Line Item. The amount must be a positive number and cannot exceed the available credit of the corresponding Invoice Line Item.|
A result parameter is returned for each request parameter.
Create Direct Credit Memo API returns an error if:
- The specified invoice does not exist.
- The status of your specified invoice is not Approved.
Your specified reason code is invalid. Reason code can be null or one of the picklist values declared in the Reason Code field of Credit Memo object.
Create Direct Credit Memo API does not support the following reason codes:
- Wallet Application
- Credit & Rebill
- Credit Amount is negative or 0.
- Template ID does not exist.
- Template Type is other than Credit Memo.
- Specified Invoice Line Item does not exist.
- Specified Invoice Line Item does not belong to the specified invoice.
- Invoice Line Item is already referenced in more than one Credit Memo Line Item.
- Credit Amount is greater than the Available Credit.
Apttus_Billing.DirectCreditMemoInput dcm = new Apttus_Billing.DirectCreditMemoInput(); dcm.autoApplyCreditMemo = true; dcm.autoApprove = true; dcm.calculateTax = true; dcm.creditMemoLineItemInputs = null; dcm.invoiceId = 'a5F5x000001hqtJ'; dcm.isFullCredit = true; dcm.reasonCode = 'Refund'; dcm.templateId = 'a03f200000lccG2'; List<Apttus_Billing.DirectCreditMemoInput> creditMemoInputs = new List<Apttus_Billing.DirectCreditMemoInput>(); creditMemoInputs.add(dcm); List<Apttus_Billing.DirectCreditMemoResult> actualCreditMemoResults = Apttus_Billing.BillingService.createDirectCreditMemosAsync(creditMemoInputs);