Updating Custom Geckoboard Widget

27 July 2012

This is a quick guide that demonstrates how to update a custom Widget on Geckoboard with the result of a Data Synchronisation using the Project Automation Feature.

Note: Requires Data Synchronisation Studio Release 3.0.570 or greater.

First you need an account at Geckoboard you can signup for a free trial to test it out.

Once you have your first Dashboard add a Custom Widget and configure it for Push, here I selected the Text widget that were just going to push a Single Text value to. You need to make a note of the Push URL and get your API key form your Account that we need in Data Sync Later.

Custom Widget

Now that you have the widget on your dashboard we need to send it some data.

Widget

This example uses a demo Data Sync project you can download but you can use any Data Source you like such as CRM, SharePoint, SQL etc.

First we setup our Data Source and preview the Data from Data Source A.

Preview A

This is a single item that were going to send to Geckoboard, next Export this result to an XML file from the Toolbar so we have a Datasource that we can connect Datasource B to and handle change events.

Connect Datasource B to the .NET XML Dataset provider by browsing to the XML file we just created.

Connect

You now have a simple Data Sync project set up that Updates the XML file when there are changes to the Source Data.

Project

Compare Results

Now for the clever bit, switch to the Project Automation Tab and enable Project Automation so that we can send the results to Geckoboard.

We need to write the code that generates the Json payload to send to Geckoboard this is quite simple with .NET Anonymous types.

Within the End method of the Project Automation which occurs after the synchronisation to the XML file and therefore only updates Geckoboard when changes occur add the following code. [Update widgetUrl and apiKey with your values].

public override void End(ProjectAutomationResult result)
    {
        if ( result.Success && result.HasChanges ) 
        {
            string widgetUrl = "https://push.geckoboard.com/v1/send/aaabbbccc";
            string apiKey = "aaabbbcccc";
            
            var data = new 
            { 
                    api_key = apiKey, 
                    data = new 
                    {                         
                        item = new []  
                        { 
                            new 
                            { 
                                text = result.CompareResult.Updated[0].SourceRow[1].BeforeColumnValue, 
                                value = result.CompareResult.Updated[0].SourceRow[0].BeforeColumnValue 
                            } 
                        } 
                    }
            };
                    
            var client = new System.Net.WebClient();
            client.UploadString(widgetUrl, Json.Encode(data));            
        }
    }

The CompareResult object contains the results of the Comparison and in this case were only interested in Updates. the Updated object is an Array of Updated Rows and the SourceRow object links back to the Datasource A row. The index of the Columns match the Schema Map layout.

And then after the Sync you will see your Geckoboard updated.

Geckoboard

| |