Build a Workflow to Ignore $0 Invoices to Send to NetSuite
Use Case
Action: Develop a workflow in Zuora to streamline the NetSuite synchronization process by ignoring zero-dollar invoices.
Description: The workflow is designed to stop the transfer of zero-dollar invoices to NetSuite during the synchronization process. Specifically, the workflow queries for zero-dollar invoices associated with a subset of Product Rate Plans and then sets the Transferred to Accounting
field to 'Ignore' to prevent them from being processed further.
Filter Logic: Identify payments from the past 24 hours where the PaymentMethodTypeSyncedToNS__c
field is not set to TRUE.
Schedule: Run Hourly
Steps to Create the Workflow in Zuora
To create the workflow described in the document for updating the Payment Method ID in Zuora and sending it to NetSuite, you would follow the steps below.
High Level Description:
Access Zuora API Sandbox
Create a New Workflow
Setup Workflow Housekeeping
Retrieve Zero Dollar Invoices (Object Query)
Iterate Over Invoices (Iterate)
Fetch Invoices (Query)
Determine Whether to Update (Javascript)
Apply Logical Instruction (IF)
Update the Invoice
Full Workflow Diagram
1. Access Zuora API Sandbox
Start by logging into the Zuora API Sandbox environment. This environment allows you to develop and test your workflows before deploying them to production.
2. Create a New Workflow
Navigate to the Workflows section in Zuora and create a new workflow.
3. Set Up Workflow Housekeeping
To manage different environments, use the following JavaScript code snippet to define your settings:
exports.step = function test(input) {
var settings = { };
//Below are prod values -- uncomment and comment out sandbox values below
settings.productRatePlanIds = [
"2c92a008707bca5c01708c92604e5523",
"2c92a008707bca5e01708c98ab025bab",
"6ad0884e83734936018380851e08028b"
];
//below are sandbox values. Comment out and uncomment above for production.
/*settings.productRatePlanIds = [
'2c92c0f87911e3330179138f4cca4562',
'6c92c0f95fc76708014fc986903d3904',
'2c92c0f76ff08d05016ff6e06dba2c62'
];*/
settings.fourHoursAgo = new Date(new Date().setHours(new Date().getHours() - 12));
//settings.fourHoursAgo = new Date(new Date().setHours(new Date().getHours() - 4));
return settings;
};
4. Retrieve Zero Dollar Invoices
Use the following criteria to query for zero-dollar invoices:
CreatedDate >= {{ Data.settings.fourHoursAgo }}
and Amount = 0
and Status = 'Posted'
and TransferredToAccounting != 'Ignore'
5. Iterate Over Invoices
Once the zero-dollar invoices have been retrieved, the workflow will iterate over each invoice.
6. Fetch Invoices
For each of the invoices we picked up in the Object Query, we now need to pull down more data from related objects. To do this, we use a Query task:
7. Determine Whether to Update
In this step, the workflow will determine if the Transferred to Accounting
field needs to be updated based on the invoice's Product Rate Plan ID:
exports.step = function test(input) {
var ret = {shouldProcess: true};
if (input.Invoice.invoice.TransferredToAccounting == 'Ignore') {
ret.shouldProcess = false;
return ret;
}
for (var i=0; i<input.Invoice.invoice.invoiceitems.length; i++) {
var item = input.Invoice.invoice.invoiceitems[i];
var id = item.RatePlanCharge.RatePlan.ProductRatePlanId;
if (input.settings.productRatePlanIds.includes(id)) {
ret.shouldProcess = false;
}
}
return ret;
};
8. Apply Logical Instruction
In this step, we determine from the output of the javascript task if we should proceed with processing the result:
{% if Data.processResults.shouldProcess == true %}
True
{% else %}
False
{% endif %}
9. Update the Invoice
If the conditions are met, update the invoice to set the TransferredToAccounting
field to 'Ignore':
{ "invoices" : [
{"id": "{{Data.Invoice.invoice.Id}}"
, "transferredToAccounting": "Ignore"
}
]}
10. Workflow Settings
Configure the workflow settings to ensure it runs hourly and processes invoices within the correct time frame, using the logic outlined above.