Skip to main content

when i am calling snippet from HTML template , getting following error -


– Uncaught TypeError: Cannot read property ‘item’ of undefined


code -
{{Alert_Message__c}}


whereas snippet works fine when called from Row Action.

Hi Sumeet,

Are you calling the snippet from a template component or from a template field inside a component? Could you post the code for the snippet?

Thanks!
Amy


Hi Amy,

I am calling snippet from template field inside component.

Snippet code-

var $ = skuid.$,args = arguments[0],
item = args.item,
list = args.list,
model = args.model;

var loggedInUser = skuid.model.getModel(‘LoggedInUser’);
var userRow = loggedInUser.getFirstRow();

var currentUserModel = skuid.model.getModel( ‘UnReadModelPA’ );
var currentUserReadModel1 = skuid.model.getModel( ‘ReadModelDesktop’ );
var currentUserReadModel2 = skuid.model.getModel( ‘ReadModelOnline’ );
var alertId = currentUserModel.getFieldValue( item.row, ‘Id’ ) ;


//create row in ReadAlerts
if(item.row.Alert_Type__c == ‘Desktop’){
var new_row = currentUserReadModel1.createRow(

additionalConditions: 
t
{ field: ‘Alert_Name__c’, value: alertId},
{ field:‘Name__c’, value: item.row.Name },
{ field: ‘User_Name__c’, value: userRow.Id }
],
doAppend: true
});

//Save ReadAlerts
$.when(currentUserReadModel1.save()).done(function(){

var TAB_SET_ID = ‘AlertTabSet’;
var c = skuid.component.getById(TAB_SET_ID);
var modelsToLoad =;
//modelsToLoad.push(currentUserReadModel1);
modelsToLoad.push(currentUserModel);

skuid.model.updateData(modelsToLoad);
window.location.reload();
//c.render();

});
} else if(item.row.Alert_Type__c == ‘Online’){
var new_row = currentUserReadModel2.createRow(

additionalConditions: 
(
{ field: ‘Alert_Name__c’, value: alertId},
{ field:‘Name__c’, value: item.row.Name },
{ field: ‘User_Name__c’, value: userRow.Id }
],
doAppend: true
});

//Save ReadAlerts
$.when(currentUserReadModel2.save()).done(function(){

var TAB_SET_ID = ‘AlertTabSet’;
var c = skuid.component.getById(TAB_SET_ID);
var modelsToLoad =;
//modelsToLoad.push(currentUserReadModel2);
modelsToLoad.push(currentUserModel);

skuid.model.updateData(modelsToLoad);
window.location.reload();
//c.render();

});
}


Hi Sumeet,


You are getting this error because you want to read the item property of args which is undefined. When you call a Skuid Snippet with a row action, Skuid provides you with the argument params (which contain the context model, row and other useful stuff).

But you are calling the snippet without any params supplied (and not Skuid managed).

You need to figure out what exactly you need to supply as params, or (worst case) rewrite your snippet.


Your call from the template should then look something like this:



<a href="javascript:skuid&#46;snippet&#46;getSnippet('ReadActionSnippetPA')(<b>'asd'</b>);">asd</a>

But of course instead of the string ‘asd’ you probably want to supply an ID of a row or some other context you need in your snippet (this can also be an object, you just have to assemble it in the template using a standard HTML script tag and write some js code there as well).


Cheers


Reply