-3

I'm using the code below but it is no showing any chart, is there an obvious reason why?

 < script type="text/javascript" src="http://google.com/jsapi"></script>
      <script src="/soap/ajax/19.0/connection.js" type="text/javascript" />
      <script type="text/javascript">
      formatCurrencyLabel = function( value ){
        return "$" + String(value);
      }

      google.load("visualization" , "1" , {package:["ColumnChart"]});
      google.setOnLoadCallback(Chart);

      function Chart(){

        data.addColumn(‘string’, ‘Timeframe’);
        data.addColumn(‘number’, ‘Gold’);
        data.addColumn(‘number’, ‘Platinum’);
        data.addColumn(‘number’, ‘Millinium’);

        sforce.connection.sessionId = ‘{!$Api.Session_ID}’;
        var date = new Date();
        var dateMin = date.setMonth(date.getMonth() -13);
        var date = new Date();
        var dateMax = date.setMonth(date.getMonth() +1);
        var soql = "Select id,name,GOLD_Policies_InForce__c, MNS_Policies_InForce__c, PLAT_Policies_InForce__c, Producer_Name__c, Type__c, Producer_Code__c  from Analytics__c where Producer_Name__c ='TestABC2' and Period__c ='21' and CreatedDate <" + convertToISO(dateMax) + " and convertToISO(CreatedDate) > " + dateMin + " Order by CreatedDate asc ";


var result = sforce.connection.query(soql);
            var it = new sforce.QueryResultIterator(result);
            while(it.hasNext()) {
                var record = it.next();
                data.addRow(['record.CreatedDate'{
                    v:parseFloat(record.PLAT_Policies_InForce__c),
                    f:formatCurrencyLabel(record.PLAT_Policies_InForce__c)
                  },{
                    v:parseFloat(record.PLAT_Policies_InForce__c),
                    f:formatCurrencyLabel(record.PLAT_Policies_InForce__c)
                  },{
                    v:parseFloat(record.GOLD_Policies_InForce__c),
                    f: formatCurrencyLabel(record.GOLD_Policies_InForce__c)
                  }
                ]);
            }
            var options = {'title':'Policies Inforce Rolling 13 Months' , legend: 'left' ,
                          'width':560,
                          'height':228,
                          'colors' : ['green','orange','#B5C5D7']
                          };
            var chart = new google.visualization.ColumnChart(document.getElementById('chart'));
            chart.draw(data , options);
        };
        </script>
        <body><div id="chart"></div></body>  

I am getting error message like.

uncaught exception: {faultcode:'sf:INVALID_FIELD', faultstring:'INVALID_FIELD: ='TestABC2' and Period__c ='21' and CreatedDate <'1367152811508' and ^ ERROR at Row:1:Column:214 value of filter criterion for field 'CreatedDate' must be of type dateTime and should not be enclosed in quotes', detail:{InvalidFieldFault:{exceptionCode:'INVALID_FIELD', exceptionMessage:' ='TestABC2' and Period__c ='21' and CreatedDate <'1367152811508'

  • could you check than sforce.connection.sessionId is getting the right value ? Also would be useful to check record value by console. In addition, you don't have to add < body > tag in VF – Martin Borthiry Mar 28 '13 at 11:47
  • btw, try to resume the topic of your question in subject, and explain as best as you can your question in the body. – Martin Borthiry Mar 28 '13 at 11:49
  • Are there any errors in the javascript console? That'd be the first thing to check – Matt Lacey Mar 28 '13 at 12:15
  • I am getting error message like. uncaught exception: {faultcode:'sf:INVALID_FIELD', faultstring:'INVALID_FIELD: ='TestABC2' and Period__c ='21' and CreatedDate <'1367152811508' and ^ ERROR at Row:1:Column:214 value of filter criterion for field 'CreatedDate' must be of type dateTime and should not be enclosed in quotes', detail:{InvalidFieldFault:{exceptionCode:'INVALID_FIELD', exceptionMessage:' ='TestABC2' and Period__c ='21' and CreatedDate <'1367152811508' – M.Reddy Mar 28 '13 at 12:47
  • 5
    those comments are helpful, but very hard to read, instead edit the question to add the useful info. The more effort you put into making your question concise, too the point, legible, and with full details, the better your answers are going to be – Ralph Callaway Mar 28 '13 at 17:36
1

According to your error message, you only have to set dateMax and dateMin as timestamps format YYYY-MM-DDThh:mm:ssZ. Just removing the extra quotes and format the date vars it should work.

There your have a js function to convert to iso format https://stackoverflow.com/a/6272061/356042

Change this

 var result = sforce.connection.query("Select id,name,GOLD_Policies_InForce__c," +
            "MNS_Policies_InForce__c, PLAT_Policies_InForce__c, " +
            " Producer_Name__c, Type__c, Producer_Code__c " +
            "from Analytics__c " +
            "where Producer_Name__c ='TestABC2' and Period__c ='21' " +
            "and CreatedDate <'" + dateMax + "' and CreatedDate >'" + dateMin + "'" +
            " Order by CreatedDate asc");

by this

 var soql = "Select id,name,GOLD_Policies_InForce__c, MNS_Policies_InForce__c, PLAT_Policies_InForce__c, Producer_Name__c, Type__c, Producer_Code__c  from Analytics__c where Producer_Name__c ='TestABC2' and Period__c ='21' and CreatedDate <" + convertToISO(dateMax) + " and convertToISO(CreatedDate) > " + dateMin + " Order by CreatedDate asc ";

console.log(soql);
var result = sforce.connection.query(soql);

Check the formed soql by console, and try it into Developer console.

  • It showing the error SyntaxError: unterminated string literal [Break On This Error] CreatedDate <" + dateMax + " and CreatedDate >" + dateMin + " + – M.Reddy Mar 28 '13 at 13:03
  • hmm, I don't see any missing quote. I edited my answer, try this form – Martin Borthiry Mar 28 '13 at 13:38
  • I have tried with that soql .And showing error like SyntaxError: missing ; before statement [Break On This Error] console.log(soql); Thanks. – M.Reddy Mar 28 '13 at 13:56
  • sorry, remove the console.log(soql); or change , by ; – Martin Borthiry Mar 28 '13 at 13:58
  • 5
    @M.Reddy you've really got to put some more elbow grease into this. It doesn't seem like you're trying to work out anything on your own. – Ralph Callaway Mar 28 '13 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.