When I call Record.transform() on a Sales Order, t...
# ask-stanley-ai
a
When I call Record.transform() on a Sales Order, to transform it to an Invoice, the Due Date doesn't automatically update based on the Terms field as it does when Terms are selected in the UI. What is the proper way to get Due Date to initialize in this scenario?
c
AI generated answer (using internal Slack threads):
When you transform a Sales Order to an Invoice using
Record.transform()
, the Due Date doesn't automatically update based on the Terms field as it does when Terms are selected in the UI. This is because the
Record.transform()
function does not automatically calculate and set the Due Date based on the Terms field. To get the Due Date to initialize in this scenario, you need to manually calculate the Due Date based on the Terms field and set it in the transformed record. Here is a sample code snippet:
Copy code
javascript
var invoiceRecord = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: so.id,
    toType: record.Type.INVOICE
});

// Calculate the Due Date based on the Terms field
var terms = invoiceRecord.getValue({fieldId: 'terms'});
var dueDate = calculateDueDateBasedOnTerms(terms); // You need to implement this function

// Set the Due Date in the transformed record
invoiceRecord.setValue({
    fieldId: 'dueDate',
    value: dueDate
});

var invoiceId = invoiceRecord.save();
Please note that you need to implement the
calculateDueDateBasedOnTerms()
function to calculate the Due Date based on the Terms field. This function should take the Terms field value as input and return the calculated Due Date. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835388184
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.831970274
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.828796387
Please provide your feedback on this answer.
Thank you for your feedback
a
Tuns out there's a script installed before I started working here, that sets the due date to today, if the billing start date is more than 90 days ago. It overwrites everything I do in my MapReduce script.