I have a custom function which has no errors in syntax, but when I try to save it, Make throws an ‘Unknown exception’ with message “value too long for type character varying(5000)”. I am not sure what validation Make is running on saving of the function. Has anyone faced this issue before? My function is pasted below:
function GroupByApp(inputArray){
const debugMode = 1;
const appFriendlyNames = {
'olk.exe': 'Outlook',
'POWERPNT.EXE': 'PowerPoint',
'ms-teams.exe': 'Microsoft Teams',
'EXCEL.EXE': 'Excel',
'slack.exe': 'Slack',
'explorer.exe': 'File Explorer',
'WINWORD.EXE': 'Word',
'CamtasiaStudio.exe': 'Camtasia Video Editor',
'SnagitEditor.exe': 'SnagIt',
'WhatsApp.exe': 'WhatsApp Web',
'Microsoft.Media.Player.exe': 'Media Player'
};
let employeeData = [];
let today = new Date();
today.setHours(0, 0, 0, 0); // Set to start of today
let yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1); // Set to start of yesterday
inputArray.forEach(collection => {
let logTime = new Date(collection.time);
logTime.setHours(0, 0, 0, 0); // Set to start of the log's date
// Process only if the log is from yesterday
if (logTime.getTime() === yesterday.getTime()) {
let user = collection.user;
let userIndex = employeeData.findIndex(u => u.employee === user);
// Initialize user data if not already present
if (userIndex === -1) {
employeeData.push({
employee: user,
totalDuration: 0,
firstLog: collection.time,
lastLog: collection.time,
apps: [],
browserWebsites: []
});
userIndex = employeeData.length - 1;
}
let userObject = employeeData[userIndex];
let duration = parseFloat(collection.duration); // Convert duration to a number
// Update total duration regardless of the duration of the individual activity
if (!isNaN(duration)) {
userObject.totalDuration += duration;
}
// Update firstLog and lastLog
let currentTime = new Date(collection.time);
if (new Date(userObject.firstLog) > currentTime) {
userObject.firstLog = collection.time;
}
if (new Date(userObject.lastLog) < currentTime) {
userObject.lastLog = collection.time;
}
}
let app = collection.executable;
let friendlyAppName = appFriendlyNames[app] || app; // Translate to friendly name
// In debug mode, add all apps and websites without filtering
if (debugMode === 1) {
let appIndex = userObject.apps.findIndex(a => a.name === friendlyAppName);
if (appIndex === -1) {
userObject.apps.push({ name: friendlyAppName, duration: duration });
} else {
userObject.apps[appIndex].duration += duration;
}
if (app === 'chrome.exe' || app === 'msedge.exe') {
let website = collection.website || 'Unknown';
let websiteIndex = userObject.browserWebsites.findIndex(w => w.name === website);
if (websiteIndex === -1) {
userObject.browserWebsites.push({ name: website, duration: duration });
} else {
userObject.browserWebsites[websiteIndex].duration += duration;
}
}
} else {
// Normal mode with filters
// Handle browser separately for productivity -1, 0, and 1
if ((app === 'chrome.exe' || app === 'msedge.exe') && (collection.productivity === -1 || collection.productivity === 0 || collection.productivity === 1)) {
let website = collection.website || 'Unknown';
// Exclude 'activtrak.com' domain
if (!website.includes('activtrak.com')) {
let websiteIndex = userObject.browserWebsites.findIndex(w => w.name === website);
if (websiteIndex === -1) {
userObject.browserWebsites.push({ name: website, duration: duration });
} else {
userObject.browserWebsites[websiteIndex].duration += duration;
}
}
} else if ((collection.productivity === 0 || collection.productivity === 1) && duration >= 60) {
// Process apps only for productivity 0 and 1
let appIndex = userObject.apps.findIndex(a => a.name === friendlyAppName);
if (appIndex === -1) {
userObject.apps.push({ name: friendlyAppName, duration: duration });
} else {
userObject.apps[appIndex].duration += duration;
}
}
}
});
// Sort apps and browser websites by duration, descending
employeeData.forEach(userObject => {
userObject.apps.sort((a, b) => b.duration - a.duration);
if (userObject.browserWebsites.length > 0) {
userObject.browserWebsites.sort((a, b) => b.duration - a.duration);
}
});
return employeeData;
}