Last updated June 25, 2019
Use Task Forms and Standards to enforce a datapoint entry.
When you want to leverage Task forms and Standards to enforce entry of a datapoint such as a Tracking Number that can be leveraged by notifications
Specify which Datapoint (Name and Code) you want created as well as reference the Metric, Name and Code, you created within the code snippet
Note: you do not have to create the datapoint in the admin app, this rule will create it on the fly
const axios = require('axios');
const METRIC_CODE = 'tracking_#';
const DATAPOINT_CODE = 'tracking_number';
const DATAPOINT_TITLE = 'Tracking Number';
module.exports = function({ headers, body }, cb) {
const metrics = body.formData.metrics.filter(m => m.code === METRIC_CODE);
if (metrics.length === 0 || !headers['x-factoryfour-token']) {
return cb(null, {});
}
const value = metrics[0].value;
const token = headers['x-factoryfour-token'];
const data = {
parent: `f4::order::${body.orders[0].id}`,
content: {
value: `${value}`,
title: DATAPOINT_TITLE,
},
format: 'string',
type: DATAPOINT_CODE,
permissions: body.parentWorkflows[0].permissions,
};
return axios({
url: 'https://api.factoryfour.com/datapoints/',
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
data,
})
.then(() => {
return cb(null, {});
})
.catch(err => {
console.log(err);
return cb(err);
});
};