Last updated March 24, 2019
Set Due Date from Requested Date in the form with a lead time.
When you want to set Due Date automatically from the Order Form you need to do it through the Requested Date. Since the Order Form can be extended to an external party, but only the internal organization has control over Due Date, you must specify a ‘Requested Date’ through the form and use a code snippet to set a ‘Due Date’ off of the ‘Requested Date’
Make sure you have loaded axios
In the below part of the snippet, replace N
with the number of days you want the ‘Due Date’ to be out from ‘Requested’
due: new Date(+(new Date(neededDate)) + (N) * 86400000).toISOString()
Note: If you want Due Date= Requested Date, put 0, if you want a week lead time, put 7…
const axios = require('axios');
module.exports = function(context, cb) {
const neededDate = context.body.order.dates.needed;
if (neededDate) {
const orderUpdate = {
dates: {
due: new Date(+(new Date(neededDate)) + (N) * 86400000).toISOString(),
}
};
const token = context.headers['x-factoryfour-token'];
const url = `https://api.factoryfour.com/orders/${context.body.order.id}`;
axios({
method: 'PUT',
url,
headers: {
Authorization: `Bearer ${token}`,
},
data: orderUpdate,
})
.then(response => console.log(JSON.stringify({response})))
.catch(err => console.log(JSON.stringify({err})));
}
cb(null, 'ok');
};