Can you use exportData() in a snippet and export data from a table without the column headers?

  • 1
  • Question
  • Updated 1 year ago
  • Answered
I'm looking to provide end users with the ability to export data from a table to a .csv file without column headings (field name/labels). Is this possible with the current exportData() method?

Thanks - Jeff Rutter
Photo of Jeff Rutter

Jeff Rutter

  • 1,162 Points 1k badge 2x thumb

Posted 1 year ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Jeff,

Jack Sanford posted an export snippet here-> https://community.skuid.com/skuid/topics/export_to_excel_without_a_table?topic-reply-list%5Bsettings...

I modified his script and 'left out' the field labels.  Here is a sample page based on Tasks.
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Task">
    <models>
        <model id="Task" limit="100" query="true" createrowifnonefound="false" datasourcetype="salesforce" datasource="salesforce" sobject="Task">
            <fields>
                <field id="Subject"/>
                <field id="CreatedDate"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
    </models>
    <components>
        <pagetitle model="Task" uniqueid="sk-3KScRx-83">
            <maintitle>
                <template>{{Model.labelPlural}}</template>
            </maintitle>
            <subtitle>
                <template>Home</template>
            </subtitle>
            <actions>
                <action type="multi" label="Export Tasks" uniqueid="sk-3KSfkM-126">
                    <actions>
                        <action type="custom" snippet="exportSnippet"/>
                    </actions>
                </action>
                <action type="savecancel" uniqueid="sk-3KScRv-82"/>
            </actions>
        </pagetitle>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript>
            <jsitem location="inlinesnippet" name="exportSnippet" cachelocation="false">var $ = skuid.$;
                
                var today = new Date();
                var model = skuid.model.getModel('Task');
                
                var fields = [
                //use the api names of your fields here
                    'Subject',
                    'CreatedDate'    
                ];
                
                var fieldsWithCorrectLabels = $.map(fields, function(v){
                    var actualField = model.getField(v);
                     console.log(actualField.id);
                     
                     return {
                        id: actualField.id,
                        name: actualField.name
                    };    
                });
                
                model.exportData({
                    fileName: 'Custom Export File Name '+today+'.csv',
                    fields: fieldsWithCorrectLabels,
                    doNotAppendRowIdColumn: true
                    });</jsitem>
            </javascript>
        </resources>
        <styles>
            <styleitem type="background" bgtype="none"/>
        </styles>
    </skuidpage>
Thanks,

Bill