You need to sign in to do that
Don't have an account?
Leebies
Problem with Whatid in Timeline S-Control Mashup
Hi!
I am trying to display tasks and events using the Timeline S-Control Mashup for a custom object. In this example called projects1. I took out all the code for the opportunities, cases etc as I dont wish to use those features. The issue is, I cant get the tasks or events to appear on the timeline. I assume it is because I need to set the whatid, however I dont know where to put it. I THINK the what ID is the 3 letters in the link example a01. Can someone help me identify what the whatid is and where it goes in the script?
Here is the script that I have edited so far:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Timeline</title> <link href="/dCSS/Theme2/default/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" > <!-- Include the MIT timeline library and CSS--> {!INCLUDE($SControl.Timeline_CSS)} {!INCLUDE($SControl.Timeline_mit_lib)} <!-- Apex AJAX connection library change--> <script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script> <script type="text/javascript"> var theTimeLine; var eventSource; var baseURL = window.location.protocol + '//' + window.location.hostname; var isProject = new Boolean("{!$Request.eid}" == "{!Project1__c.Id}"); // see what tab we are called from function validId(id) { return ("{!$Request.eid}" != null && "{!$Request.eid}" != "" && "{!$Request.eid}" === id); } var hasActivities = new Boolean( isProject == true ); function _WhatId() { if (isProject == true) return "{!Select p.Id from Project1__c p}"; return null; } var WhatId = _WhatId(); /************************** * load the timeline UI, then query for events to add * all the events are added async to give a quicker load */ function initPage() { //build the timeline widget eventSource = new Timeline.DefaultEventSource(); var theme = Timeline.ClassicTheme.create(); theme.event.label.width = 300; // px this will truncate the labels that appear on the timline //theme.event.bubble.width = 250; //theme.event.bubble.height = 200; theme.ether.backgroundColors.unshift("#f3f3ec"); // set up the bands of info in the display var bandInfos = [ Timeline.createBandInfo({ eventSource: eventSource, date: Date(), width: "80%", intervalUnit: Timeline.DateTime.MONTH, intervalPixels: 100, theme: theme }), Timeline.createBandInfo({ showEventText: false, trackHeight: 0.5, trackGap: 0.2, eventSource: eventSource, date: Date(), width: "20%", intervalUnit: Timeline.DateTime.YEAR, intervalPixels: 200 }) ]; bandInfos[1].syncWith = 0; bandInfos[1].highlight = true; theTimeLine = Timeline.create(document.getElementById("my-timeline"), bandInfos); /************* * begin DATA queries * each query kicks off an async callback to plot/load the results, does not wait for all before drawing. * more can be added to support custom objects, to support custom objects, test for merge fields * decide what related records have dates, and create a layout callback for each. * this can also be used to support one scontrol on many different object page layouts * so, contact, opportunity, account or case can all run from this one scontrol * we do assume it is an inline scontrol */ if ( hasActivities == true && WhatId != null ) { //get all tasks related to this object ( must have a WhatId) sforce.connection.query( "Select Id,Subject,Status,ActivityDate,Description,CreatedDate,Owner.FirstName,Owner.LastName, Who.FirstName, Who.LastName from Task where WhatId='"+ WhatId +"'", layoutTasks); // events sforce.connection.query( "Select Id, Subject, Location, ActivityDateTime,ActivityDate, IsAllDayEvent, DurationInMinutes, Description, Owner.FirstName,Owner.LastName, Who.FirstName, Who.LastName from Event where WhatId='"+ WhatId + "' order by ActivityDate", layoutEvents); } } /* * layout callbacks, gets a list of query results, formats a timeline entry and bubble contents * when constructing data.events array of objects to add via loadJSON, the following are available * * { start: end: title: link: 'parent:link...' latestStart: null, earliestEnd: null, isDuration: false, description: image: img, icon: img, color: "#999", textColor: null, onclick: "javascript:..." } Note, for IE and IE7 the last data element must not have a comma following it */ function layoutTasks(qr) { layoutActivity(qr, "/img/icon/tasks16.png"); } function layoutEvents(qr) { layoutActivity(qr, "/img/icon/calendar16.png"); } function layoutTasksWhat(qr) { layoutActivityWhat(qr, "/img/icon/tasks16.png"); } function layoutEventsWhat(qr) { layoutActivityWhat(qr, "/img/icon/calendar16.png"); } // activities may have duplicates on an account for example, keep a list to avoid var seen = []; // this callback loads tasks into the timeline function layoutActivityWhat(qr,img) { loadJSON ( map ( qr.getArray('records'), function(rec,idx,ary) { if ( seen[rec.Id] ) { return null; } else { seen[rec.Id] = rec.Id;} var stdate = rec.getDate('ActivityDate'); if (!stdate) { stdate = rec.getDateTime('CreatedDate'); } return { start: stdate, title: rec.Subject + (rec.What && rec.What.Name — ', '+rec.What.Name : ''), link: 'parent:/' + rec.Id, description: 'description: ' + (rec.Description – rec.Description:'') + (rec.Who && rec.Who.FirstName && rec.Who.LastName ˜ '<br>contact: ' + rec.Who.FirstName + ' '+rec.Who.LastName : '') + "<br>assigned to: " + rec.Owner.FirstName + " " + rec.Owner.LastName, image: img, icon: img, color: "#999" } } ) ); } // this callback loads tasks into the timeline function layoutActivity(qr,img) { loadJSON ( map ( qr.getArray('records'), function(rec,idx,ary) { if ( seen[rec.Id] ) { return null; } else { seen[rec.Id] = rec.Id;} var stdate = rec.getDate('ActivityDate'); if (!stdate) { stdate = rec.getDateTime('CreatedDate'); } return { start: stdate, title: rec.Subject + (rec.Who && rec.Who.FirstName && rec.Who.LastName ™ ', '+rec.Who.FirstName + ' '+rec.Who.LastName : ''), link: 'parent:/' + rec.Id, description: 'description: ' + (rec.Description ? rec.Description:'') + (rec.Who && rec.Who.FirstName && rec.Who.LastName ? '<br>contact: ' + rec.Who.FirstName + ' '+rec.Who.LastName : '') + "<br>assigned to: " + rec.Owner.FirstName + " " + rec.Owner.LastName, image: img, icon: img, color: "#999" }; } ) ); } // some helper functions // take an array of events, load them into a data object and pass to loadJSON function loadJSON (events) { if (!events || events.length <1) return; var data = {}; data.events = events; eventSource.loadJSON(data,baseURL); // eventSource is part of the Timeline API } // call a function on each member of the array, return an array // of the results of the callbacks function map(anArray /* Array */, callback /* Function */){ var outArr = []; for(var i=0,l=anArray.length; i<l; i++){ var topush = callback(anArray[i], i, anArray); if (topush != null) { outArr.push( topush ); } } return outArr; } /*********************** * function onResize() * If the page is resized, the timeline is resized to match * this waits for resize to finish 1/2 second */ var resizeTimerID = null; function onResize() { if (resizeTimerID == null) { resizeTimerID = window.setTimeout( function() { resizeTimerID = null; theTimeLine.layout();}, 500 ); } } </script> <!-- main functions --> </head> <body onload="javascript:initPage();" onresize="javascript:onResize();" > <div id="my-timeline" style="height:300px; border: 1px solid #aaa"></div> </body> </html>
call it a limitation of SOQL, you cannot nest select like this.
rather i think you want the simpler:
WhatId = '{!Project1__c.Id}';
Message Edited by Ron Hess on 05-06-2007 09:41 AM