Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
User avatar
By groakes
#814564
Hi all,

I am trying to use Moments.js to calculate a date but am having some (probably fundamental) problems...
I have a Date variable @@requireDate which represents the due date for a piece of work.
I have a floating point variable @@estimatedTimeToDigitise which represents the number of days required to carry out the work.
I have another date variable @@digitisationStartDate which should be calculated by subracting the work effort from the required date. This is executed by a button setStartDate.

I'm using the following code:
Code: Select all
function setDigiStartDate(){
        var requireDate = $('#requireDate').getValue();
	var estimatedTimeToDigitise = $('#estimatedTimeToDigitise').getValue();
        var digiStartDate= moment(requireDate).subtract(estimatedTimeToDigitise, 'days');
        $('#digitisationStartDate').setValue(digiStartDate);
};
$('#setStartdate').click(setDigiStartDate);
However, when I enter the values and click the button nothing happens.

All help and suggestion gratefully received.

cheers
Greg
By cpomares
#814572
Hi Groakes,

I've just tested your code and everything is working ok, maybe you are getting confused with variable names. By the way what version of ProcessMaker are you using? Moment.js works on ProcessMaker from version 3 onwards.

Regards,
Carlos Pomares
User avatar
By amosbatto
#814576
Greg,
The problem is that a Moment date object cannot be the value in your setStartDate field. You need to first convert it to a string in YYYY-MM-DD format like this:
Code: Select all
function setDigiStartDate(){
        var requireDate = $('#requireDate').getValue();
	var estimatedTimeToDigitise = $('#estimatedTimeToDigitise').getValue();
        var digiStartDate= moment(requireDate).subtract(estimatedTimeToDigitise, 'days').format("YYYY-MM-DD");
        $('#digitisationStartDate').setValue(digiStartDate);
};
$('#setStartdate').click(setDigiStartDate);
User avatar
By groakes
#814582
Hi Amos,

I applied the format to the moment statement but I still get the same no result. I have attached the form for you to have a look at when you have time. I checked all the variables and they seem to be OK. Debug shows the the values for @@requireDate and @@estimatedTimeToDigitise but @@digitisationStartDate remains empty.

I'm working in 3.2.1 Community.

cheers and thanks
Greg
Attachments
(4.79 KiB) Downloaded 221 times
By cpomares
#814591
Hi groakes,

I reviewed your dynaform and I found a mistake. the id of your button is "setStartdate" and in your javascript, you are referring to it as "setStartDate" you have the letter D capitalized, I changed it and that solve the problem, however, if you still have problems with it try deleting the button and add a new one with the same id. Hope this can help you.

Regards,
Carlos Pomares
User avatar
By groakes
#814597
Thanks Carlos - newbie error :oops:

I tried deleting and re-adding the button and no joy. :?

In the end I deleted all the fields in the form, re-added them and...

...it Worked!!! :D

I'm not sure what went on there but I have a working form so big thanks for all your help!!

thanks
Greg

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]