Hi Everyone,
We have a requirement to start tracking what pages are being visited by the various users. To that end we created a simple object with two fields. PageName__c and URI__c. I wanted to create a static resource that we can just add to the page when we want to audit, and this could capture the URI.
So we build the code, and it does insert a record, but the fields are not getting populated with any data and I am at a loss. The user has rights since we can open the Audit table and edit the fields, so I don’t believe we have a security issue.
Any insights are greatly appreciated!
((function(skuid) {
skuid.$(document.body).one(‘pageload’,function(){
//set initial variables
var currentLocation = window.location.href, curModel;
//check if the model already exists and so do not create it again
if(skuid.model.getModel(‘LOISAuditLog’)==‘undefined’|| skuid.model.getModel(‘LOISAuditLog’)==null)
{
console.log(“Creating LOISAuditLog Model”);
curModel = new skuid.model.Model();
curModel.objectName = ‘System_Audit_Log__c’;
curModel.id = ‘LOISAuditLog’;
curModel.recordsLimit = 1;
curModel.fields =
{ id: ‘URI__c’ },
{ id: ‘PageName__c’}
];
curModel.initialize().register();
}
else
{
//Model exists, so just set the curModel to the existing one for the page load
console.log(“Audit Log Model Already Exists”);
curModel = skuid.model.getModel(‘LOISAuditLog’);
}
// Insert the new record into the Audit Table
curModel.createRow();
curModel.updateRow(curModel.getFirstRow(),{URI__c:currentLocation});
// Save the record
curModel.save({callback: function(result){
if (result.totalsuccess) {
console.log(‘Audit Log Entry Created’);
console.log(curModel.getFirstRow());
} else {
console.log(‘There was an error saving the Audit Record’);
console.log(result.insertResults);
console.log(result.updateResults);
console.log(result.deleteResults);
}
}});
});
}))(skuid);