Can you automatically take an image of a chart and attach it to a record?

  • 2
  • Question
  • Updated 7 hours ago
I'd like to create a button that in one click attaches an image of a chart to a record in Salesforce.

I can conceive of some javascript that would either target the hamburger icon on a chart and click it, OR access the highcharts library directly so that you could have a download by clicking a button.

Is there any javascript that can create an attachment on a Salesforce record from a given file? 

My use case is we have a Meetings module where an agenda item could display a chart, and after the meeting is over we need to preserve exactly what was seen in the meeting. So I'm looking for a button "Lock Meeting" that would create an image of exactly what the chart is displaying at the time and attach to the agenda item. 
Photo of Jack Sanford

Jack Sanford, Champion

  • 9,550 Points 5k badge 2x thumb
  • curious

Posted 4 weeks ago

  • 2
Photo of Bill McCullough

Bill McCullough, Champion

  • 13,250 Points 10k badge 2x thumb
Jack,

I helped with some Skuid page builds that were targeted for use on a tablet.  What I saw is that when you click the File Upload 'button', the tablet presented an option to take a picture along with uploading a file from the device.  I think you should test this with your page.  You may not need any JavaScript.

Thanks,

Bill
Photo of Jack Sanford

Jack Sanford, Champion

  • 9,550 Points 5k badge 2x thumb
Thanks Bill, but not quite what I'm looking for. 

I'm looking at the Download PDF Document function on skuid's charts components. I'd like a button that automatically creates that PDF and attaches it to a given record id. 


Photo of Jack Sanford

Jack Sanford, Champion

  • 9,550 Points 5k badge 2x thumb
Thanks Bill. Any ideas on how to select the chart from within skuid? The snippets from highcharts have the chart being created within the JS snippet, or that stack overflow link suggests using var chart = $('#container').highcharts();

I can select my chart's div using document.querySelector('#chartUniqueId') but that's not anywhere close to the actual chart itself. 

In the console inspection, it appears that there's a div with a class of highcharts-container, but the id of that div changes on every page load. I would need to "select the div with the class highcharts-container that is a child of the child of the child of the div with the id of myChartUniqueId

Photo of Jack Sanford

Jack Sanford, Champion

  • 9,550 Points 5k badge 2x thumb
I think there's some way to make the drop down menu do this instead of showing the drop down menu. You can add an onclick function to it, and even change the icon

https://api.highcharts.com/highcharts/exporting.buttons.contextButton
Photo of Zach McElrath

Zach McElrath, Employee

  • 52,256 Points 50k badge 2x thumb
This sounds like a great candidate for a Component Action on the Chart component --- so that you could have a button which lets you declaratively capture the chart as a PDF / JPEG and then allow you to store it to the locations that we support for the File Upload component, e.g. for Salesforce, attachments / content documents / etc. Would also be great to be able to just initiate the download using your own custom buttons instead of relying on the user to click the icon.
Photo of Jack Sanford

Jack Sanford, Champion

  • 9,540 Points 5k badge 2x thumb
Agree! I actually checked to see if it was, just in case maybe y'all had snuck it in there when I wasn't looking. :)