Skip to main content

I have two snippets and both were created based on Community user posts. I am unable to export my data and would like guidance on why this is not working. When I refresh my page it won’t even load the Page!

The reason I’m using a Button is that the default Skuid Export Option is at the bottom of the Page and would like it at the top so users can download and Print the transactions.


I’m using Skuid 15.3.14 Dubai with V1 API


-------------------Version 1:------------------


$ = skuid.$;


var tmodel = skuid.$M(‘Transactions’);


console.log("Model length: ",tmodel.length);


var fields =

tmodel.getField(‘ActivityDate’),

tmodel.getField(‘CheckNum’),

tmodel.getField(‘TransactionType’),

tmodel.getField(‘TransactionDetail’),

tmodel.getField(‘Amount’),

tmodel.getField(‘RunningBalance’)


];


tmodel.exportData({


fileName: ‘Transactions.csv’,

fields: nfields],

doNotAppendRowIdColumn: true


});


-------------------------Version2:-------------------------------------


var params = arguments-0],

$ = skuid.$;


var today = new Date();

var tmodel = skuid.model.getModel(‘Transactions’);

console.log("Number of Rows: ",tmodel.length);

var fields = ,

//use the api names of your fields here


 'ActivityDate',
'Checknum',
'TransactionType',
'TransactionDetail',
'Amount',
'RunningBalance'
];

var fieldsWithCorrectLabels = $.map(fields, function(v){

var actualField = tmodel.getField(v);


console.log(actualField.id);


return {

id: actualField.id,

name: actualField.name

};

});


tmodel.exportData({

fileName: ‘Bank Transactions ‘+today+’.csv’,

fields: fieldsWithCorrectLabels,

doNotAppendRowIdColumn: true

});

Generally a page that simply wont load means some fatal error in your javascript. A variable that cannot be found etc. Open up the developer console and there will likely be an error posted that will give you insight.


The console log statements in your code are also good checkpoints. If those values are actually generated in the developer console - you know that the code has gotten that far.


Also - is this code included in a resource of type “Inline - Snippet”


@Rob_Hatch

I discovered yesterday that when I copied and pasted part of the snippet, it did not work. Then I noticed the parts that I actually wrote were a different color (light green). So, I re-typed the pieces I pasted and behold, it worked. Details…all in the details!!


The above snippet does work now.


Thanks for the response Rob.


It’s good practice to enclose everything you put inside a javascript snippet in a try catch so that you can see errors in the console properly, otherwise the errors will not display.


for example


try{
$ = skuid.$;

var tmodel = skuid.$M(‘Transactions’);

console.log("Model length: ",tmodel.length);

var fields = l
tmodel.getField(‘ActivityDate’),
tmodel.getField(‘CheckNum’),
tmodel.getField(‘TransactionType’),
tmodel.getField(‘TransactionDetail’),
tmodel.getField(‘Amount’),
tmodel.getField(‘RunningBalance’)

];

tmodel.exportData({

fileName: ‘Transactions.csv’,
fields: rfields],
doNotAppendRowIdColumn: true

});
}catch(e){
console.error(e);
}

Mark,


Thank you. I really appreciate you for posting this. I will keep this “tip” and use it in the future.

Steven


Reply