Date converstion using script include and client script

Saurabh Singh5
Tera Expert

Hi,

 

Would need help with converting a Date from any format of the user into the system format and then validate it for 3 business days from the present day.

 

We have tried a lot of thing but at one point it works and suddenly it stops working we tried ".getNumericValue()"

but that also doesn't seem to work for different formats we need it to be set to system format and only then it works very sporadically.

1 ACCEPTED SOLUTION

Okay so i was referring to this error and got an old community post which has helped us fix the issue. by using the script: var newString= String(oldString).valueOf();

 

So, this error comes because the value being returned is a Java string, and we are trying to process it as a javascript string.

 

Community post to fix the error Ljava.lang.String;@

View solution in original post

9 REPLIES 9

Okay so i was referring to this error and got an old community post which has helped us fix the issue. by using the script: var newString= String(oldString).valueOf();

 

So, this error comes because the value being returned is a Java string, and we are trying to process it as a javascript string.

 

Community post to fix the error Ljava.lang.String;@

Nice to hear that, issue has been solved.

In that case you can mark this as closed.

 

Best Regards,

Pooja

@Saurabh Singh5

Please share your latest scripts so that it helps community members in future.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sure, Please check the script which i have used its the same as before just added the syntax from the solution provided which is marked as solution proposed.

var getplanneddatevalues = Class.create();
getplanneddatevalues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getValue: function() {

        var userdateformat = gs.getUser().getDateFormat();

        {

            var time = new GlideDateTime().getTime().getDisplayValue();
            var days = 3;
            var prschedule = gs.getProperty('scheduled_24hrsX5');
            var opened_st = new GlideDateTime();
            var duration = new GlideDuration(60 * 60 * 24 * 1000 * days);
            var schedule = new GlideSchedule(prschedule);
            var duedate = schedule.add(opened_st, duration);
            var gdt = new GlideDateTime(duedate);
            var dateMil = gdt.getNumericValue();
            var dateTi = this.getParameter('sysparm_date');
            var dateTime = this.getParameter('sysparm_date').toString().split(' ');
            var a1 = '/,-,.';
            var a4 = a1.split(',');
            var dateFor = String(gs.getUser().getDateFormat().toString()).valueOf(); // we have just added this into the script as per the original solution.
            var j;
            for (var i = 0; i < a4.length; i++) {
                if (dateFor.contains(a4[i])) {
                    j = a4[i];
                    break;
                }
            }
            var date = String(dateTime[0].toString()).valueOf();
            var time1 = dateTime[1];
            var rDate = {};
            var dateCon = date.split(j);
            var dateFor1 = dateFor.split(j);

            for (var k = 0; k < dateFor1.length; k++) {

                rDate[dateFor1[k]] = dateCon[k];

            }

            var rDateTime = rDate.yyyy + '-' + rDate.MM + '-' + rDate.dd + ' ' + time1;
			
            var gdt1 = new GlideDateTime(rDateTime);
            var startDateMil = gdt1.getNumericValue();

            if (dateMil > startDateMil) {
                return true;
            } else {
                return false;

            }
        }
    },
    type: 'getplanneddatevalues'
});

 

Thanks,

Saurabh Singh

Ankur Bawiskar
Tera Patron
Tera Patron

@Saurabh Singh5 

check this and enhance

Variable Date no less than 5 business days 

Auto-populating and validating date fields 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader