Alpha Video Training
Results 1 to 5 of 5

Thread: Java Script Problem reading date from list

  1. #1
    Member
    Real Name
    Travis Irby
    Join Date
    Oct 2017
    Posts
    27

    Default Java Script Problem reading date from list

    i am attempting to create a google time line chart from data in a list control, but have trouble getting the date fields for the list.

    var strdata = "['Well_Name','Startdate','Enddate'],"
    var lObj = {dialog.object}.getControl('list1');
    //number of rows in list.
    var count = lObj._rData.length;
    if (count == 0)
    {
    {dialog.Object}.setValue('PLACEHOLDER_1','No data found in your list. Check your data or filter settings' );
    {dialog.Object}.setControlDisplay('STATICTEXT_1',false)
    return;}
    {dialog.Object}.setControlDisplay('STATICTEXT_1',false)

    //Loop through all rows of the list and build the array string.
    for (i=0;i<count;i++) {
    strdata = strdata + "['" + lObj.getData(i).Well_Name + "','" + lObj.getData(i).Startdate + "','" + lObj.getData(i).enddate + "']," ;
    }
    //remove last comma from bottom row.
    strdata = strdata.substring(0, strdata.length - 1);
    //enclose in brackets
    strdata="[" + strdata + "]";
    {dialog.Object}.setValue('PLACEHOLDER_1',strdata);

    //This the key command that converts the string variable to a javascript object that google can consume as a parameter
    //Without this command, I kept getting "not an array error"
    var chartdataObj = eval ("(" + strdata + ")");

    //PLACEHOLDER_1 used for no records found message. Clear any value
    {dialog.Object}.setValue('PLACEHOLDER_1','');

    window.alert(strdata);

    the window alert shows the string in proper format but where the dates should be shows "undefined"
    Screen.png

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,722

    Default Re: Java Script Problem reading date from list

    Could you post an example of the array you're trying to build? An example of the data structure the Timeline chart expects?

    Be aware that field property names are case sensitive. If your field is Enddate and you ask for enddate you'll get undefined.

  3. #3
    Member
    Real Name
    Travis Irby
    Join Date
    Oct 2017
    Posts
    27

    Default Re: Java Script Problem reading date from list

    Quote Originally Posted by Davidk View Post
    Could you post an example of the array you're trying to build? An example of the data structure the Timeline chart expects?

    Be aware that field property names are case sensitive. If your field is Enddate and you ask for enddate you'll get undefined.
    this is the array i need to build before i can pass it to the chart
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Task ID');
    data.addColumn('string', 'Task Name');
    data.addColumn('date', 'Start Date');
    data.addColumn('date', 'End Date');
    data.addColumn('number', 'Duration');
    data.addColumn('number', 'Percent Complete');
    data.addColumn('string', 'Dependencies');

    data.addRows([
    ['Test1', 'Test1A',
    new Date(2017, 10, 1), new Date(2017, 10, 5), null, 100, null],
    ['Test', 'TestA',
    new Date(2017, 10, 5), new Date(2017, 10, 15), null, 100, null]
    ]);

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,722

    Default Re: Java Script Problem reading date from list

    Googles DataTable wants a date object... not a date string. I've made an assumption that you've not made any specific modifications to your List to change the incoming dates to objects... so the List is giving you date strings... which is a problem

    Next, you're method for building the arrays is not something you should be using. It's very hard to read and very, very hard to debug... and not necessary.

    Your second example code is using differing field names than your first... so I don't really know what you're going after... but using your first post, here is code that works. Again, List fieldname references are case sensitive.

    You don't need to use .getControl() to get the List control... if all you're after is it's data. Use .getListData() instead. I'm displaying the chart in a Static Text control, in a div with an id of "timeline".
    The fields from my table, and therefore from the List are: Well_Name, StartDate, EndDate.

    Code:
    google.charts.load('current', {'packages':['timeline']});
    
    	var lData = {dialog.Object}.getListData('LISTWELLS');
    	
    	var container = document.getElementById('timeline');
    	var chart = new google.visualization.Timeline(container);
    	var dataTable = new google.visualization.DataTable();
    	
    	dataTable.addColumn({ type: 'string', id: 'Well_Name' });
    	dataTable.addColumn({ type: 'date', id: 'StartDate' });
    	dataTable.addColumn({ type: 'date', id: 'EndDate' });
    	
    	debugger;
    	
    	var tcArray = [];
    	
    	for(i=0;i<lData.length;i++){
    		var tcDataArray = [];
    		var sDate = new Date();
    		var eDate = new Date();
    
    		tcDataArray.push(lData[i].Well_Name);
    		sDate.fromFormat(lData[i].StartDate,'MM-dd-yyyy')
    		tcDataArray.push(sDate);
    		eDate.fromFormat(lData[i].EndDate,'MM-dd-yyyy')
    		tcDataArray.push(eDate);
    		tcArray.push(tcDataArray);
    	}
    	
    	dataTable.addRows(tcArray);
    	
    	chart.draw(dataTable);
    Have a read through and if there's something that needs explanation, please post.

  5. #5
    Member
    Real Name
    Travis Irby
    Join Date
    Oct 2017
    Posts
    27

    Default Re: Java Script Problem reading date from list

    Thank you very much David. your example was worked perfect. The method i was using was found from an example on the the forum from previous versions of alpha. i was able to get what i was trying to work by going back to the sql query and converting the dates to string in the query and setting the list formats to character instead of date. your example is much cleaner.
    that VB.net demon in the back of my head comes out every now and then

Similar Threads

  1. Replies: 6
    Last Post: 10-01-2016, 01:01 AM
  2. Java script
    By Portal 6 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 12
    Last Post: 10-20-2013, 09:40 PM
  3. Help with Java script new Date() as default date in dialog
    By Tbrondolo in forum Application Server Version 11 - Web/Browser Applications
    Replies: 8
    Last Post: 01-21-2013, 04:26 PM
  4. Load a page without reading a Java Function
    By Willard in forum Web Application Server v6
    Replies: 2
    Last Post: 01-16-2005, 07:49 AM
  5. Problem with date script
    By Glen Beer in forum Alpha Five Version 4
    Replies: 5
    Last Post: 08-25-2003, 07:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •