Issue with updating DueDate after modifying StartDate in a handler in Creatio
Hello everyone,
I’m working on a solution that automatically adds 15 minutes to the StartDate
and assigns this new value to the DueDate
attribute in Creatio. The issue is that although the logs show the correct date (after adding 15 minutes), the DueDate
value is not updating on the page, and I still see the old value.
Here’s my code in the handler:
javascript
handlers: [ { request: 'crt.HandleViewModelAttributeChangeRequest', handler: async (request, next) => { if (request.attributeName === 'StartDate') { const startDate = request.$context.StartDate; console.log("StartDate before adding minutes: ", startDate); if (startDate) { // Add 15 minutes to StartDate const newDueDate = new Date(new Date(startDate).getTime() + 15 * 60 * 1000); console.log("DueDate after adding 15 minutes: ", newDueDate); // Assign the new value to DueDate request.$context.DueDate = newDueDate; // I also tried using $set to update the UI try { if (request.$context.$set) { request.$context.$set('DueDate', newDueDate); } } catch (error) { console.log('Error with $set method:', error); } } } return next?.handle(request); } } ]
- The logs show that the date is correctly calculated, and 15 minutes are added
- However, on the Creatio interface, I see that
DueDate
is not updating. - Even though I tried using the
$set
method to update the value, it still does not work.
**Has anyone encountered this issue before? How can I ensure that the DueDate
is updated correctly on the interface after modifying StartDate
? Any suggestions would be greatly appreciated!
Thank you in advance!
Like
First of all, are you sure the attribute for DueDate is really DueDate? I'd start with making sure you're using the correct attribute name as located on the viewModelConfigDiff.
Second, the change request not only fires when a user changes a value, but also when the page loads the data initially. If you want to only handle the change when a user changes the value, add a check for request.silent=false (silent=true means it was silently loaded on the page, not an actual change occurring).
Your if statement would look like this to only handle changes made after the page it loaded by the user:
if (request.attributeName === 'StartDate' && !request.silent) { // code here }
Ryan
It actually turned out that the attribute had a different name , but in addition I had to leave the ‘await’
const startDate = (await request.$context.StartDate);
Now it works, thank you for your help :)