Dear Sir/Madam,
I'm trying to update a card badge with custom field data. one field with the badge text, and the other for the color. My code isn't working and I was wondering if you could help, please?
The client.js file i'm using has a 'card-badges' function which i need to poll roughly once an hour. 5 secs is for debugging as is the dyunamic number. this is the code:
'card-badges': function(t, options) {
// IDs for custom fields
const STATUS_CUSTOM_FIELD_ID = '65056bd886be3b322d48606c';
const COLOR_CUSTOM_FIELD_ID = '655a1720b25d44ce1e297949';
return Promise.all([
t.get('card', 'shared', STATUS_CUSTOM_FIELD_ID, 'Status: N/A'),
t.get('card', 'shared', COLOR_CUSTOM_FIELD_ID, 'blue'),
]).then(function(results) {
// debug: console.log('Card Badges Results:', results);
console.log('Card Badges Results:', results); // Debug: Results from custom fields
// results[0] is the value from STATUS_CUSTOM_FIELD_ID
// results[1] is the value from COLOR_CUSTOM_FIELD_ID
return [{
dynamic: function() {
// Construct the badge object
return {
text: "Dynamic " + (Math.random() * 100).toFixed(0).toString(), // Text from the first custom field
color: results[1], // Color from the second custom field
refresh: 5 // Refresh the badge every 10 seconds
// icon: optional icon URL
};
}
}];
}).catch(function(error) {
console.error('Card Badges Error:', error); // Debug: Error in fetch or processing
});
},
####################
this is a function from the plugin which does work
Example logic to update statusBadge
function updateStatusBadge(t) {
const FEDEX_CUSTOM_FIELD_ID = '65056bd886be3b322d48606c';
const SHIPPING_REF_CUSTOM_FIELD_ID = '655a1720b25d44ce1e297949';
Promise.all([
t.get('card', 'shared', FEDEX_CUSTOM_FIELD_ID, 'No Tracking Data'),
t.get('card', 'shared', SHIPPING_REF_CUSTOM_FIELD_ID, 'grey')
]).then(function(results) {
// Update statusBadge with new values
t.set('card', 'shared', 'statusBadge', { text: results[0], color: results[1] });
});
}
I'm starting to pull my hair out. Please help if you can!
Many thanks,
Matt
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.