cancel
Showing results for 
Search instead for 
Did you mean: 

Updated MX_VALIDTO not saving at Database in Expected format

ganesh_s7
Participant
0 Kudos

Hi Experts,

We have a requirement that Validity end date for external users, be set upon pre-determined condition.  The UI (Task) has MX_VALIDTO in Editable format. In the workflow below the Task, Job is written to modify the validity end date via JScript.

We are facing error whenever the day or month has a zero in it. ie., 1st March which should be stored as '2015-03-01' is getting stored in Database as '2015-3-1' even though the debug line shows the returing Output as '2015-03-01'.

We have tried returning the value as String and as a Date Object, but it isn't working. The value is still getting stored without zero.

Somewhere after the data is returned by the script and before being stored in Database, the error happens. Believe we are missing something here.

Please find below the screenshots of the JScript and the Log.

Your support is highly appreciated.

Regards,

Ganesh S

Accepted Solutions (0)

Answers (2)

Answers (2)

Chenyang
Contributor
0 Kudos

Hi Ganesh,

What data type do you use to store the Z valid to dates? Did you try string/text  instead of Datetime?

Cheers,

Chenyang Xiong

ganesh_s7
Participant
0 Kudos

Hi Chenyang,

The Z attribute is Text, but the MX_VALIDTO attribute is in 'datetime format'.

We are not worried of the Z attribute value.  The error is happening in MX_VALIDTO.

BR,

Ganesh.S

Chenyang
Contributor
0 Kudos

Did you try saving text for instance "2015-05-31" into MX_VALIDTO attribute?  It seems correct.

jaisuryan
Active Contributor
0 Kudos

Hi Ganesh,

I am not well versed in JS so I couldn't point out issue in your JS.

But we had the same kinda requirement and we added 0 to string.

try the below statement and let me know if it works.

var validtodate=todateInDateFmt.getFullYear() + "-" + ("0"+(todateIntDateFmt.getMonth()+1).toString()).slice(-2)+"-"+("0"+todateIntDateFmt.getDate().toString()).slice(-2);

Kind regards,

Jai

ganesh_s7
Participant
0 Kudos

Hi Jai,

Even when we convert the value using .toString() function the values doens't get saved correctly.

BR,

Ganesh.S

jaisuryan
Active Contributor
0 Kudos

Hi Ganesh,

We passed the date in string format and it worked.

Please try the below. It comes after line 76 in your code

var monthPart = (todateInDateFmt.getMonth()+1).toString();

if(monthPart.length==1){

monthPart="0"+monthPart;

}

var datePart = (todateInDateFmt.getDate()).toString();

if(datePart.length==1){

datePart="0"+datePart;

}

var validtodate=todateInDateFmt.getFullYear() + "-" + monthPart + "-"+ datePart;

Kind regards,

Jai