Skip to main content

Here is our full code



var params = arguments[0],

$ = skuid.$;

var field = arguments[0];

var model = field.model;

var row = field.row;

var HtmlString = ‘’;

var ActName = row.Name;

var Piece = row.Piece__r;

if(Piece){

console.log(Piece.Name);

//var PieceWriterModel = skuid.model.getModel(“MMA_Music_Piece_Writer”);

//var MusicPieceCondition = PieceWriterModel.getConditionByName(“MMA_Music_PieceId”);

//var PieceId = Piece.Id;

var Piece_Name = Piece.Name;

HtmlString = ‘

’+ Piece.Name + ‘
’;

//var cellElem = field.element;
//console.log(HtmlString);
//cellElem.html(HtmlString);

}

else{

HtmlString = ActName + ‘’;

window.alert(ActName + ’ - There is no peice in thie Act.')

//cellElm = field.element;

}


var NoOfWriters = 0;

var MusicWriter =‘none’;

if(Piece){

var PieceWriterModel = skuid.model.getModel(“MMA_Music_Piece_Writer”);

var MusicPieceCondition = PieceWriterModel.getConditionByName(“MMA_Music_PieceId”);

var PieceId = Piece.Id;

PieceWriterModel.setCondition(MusicPieceCondition,PieceId);

console.log(‘After Set condition’ + PieceId + ’ PieceId ‘);

PieceWriterModel.updateData(function(){

NoOfWriters = PieceWriterModel.data.length;

if(NoOfWriters>0){

for(i=0;i<NoOfWriters;i++){

if(PieceWriterModel.dataei].MMA_Music_Composer__c){

MusicWriter = PieceWriterModel.datari].MMA_Music_Composer__r.Name;

HtmlString = HtmlString + ‘

’+ ‘&nbsp;’ + ‘&nbsp;’ + ‘&nbsp;’ + ‘&nbsp;’+ MusicWriter +’';

if(PieceWriterModel.datami].MMA_Music_Writer_Role__r){

var MusicWriterRole = PieceWriterModel.dataei].MMA_Music_Writer_Role__r.Name;

var Writer_Role_String = ‘, ‘+ MusicWriterRole +’
’;

HtmlString = HtmlString + Writer_Role_String;


                    }
else{
}}
else{
window.alert(Piece_Name + ' - This Piece does not have any associated Music Writers.');
}
}
var cellElem = field.element;
cellElem.html(HtmlString);
}
});



}
else{
cell.Elem.html(HtmlString);
}


THE PART BELOW IS NOT LOOPING PROPERLY AND IS GETTING STUCK ON THE FIRST RECORD. ANY IDEAS FOR HOW TO GET IT TO LOOP PROPERLY?


var NoOfWriters = 0;

var MusicWriter =‘none’;

if(Piece){

var PieceWriterModel = skuid.model.getModel(“MMA_Music_Piece_Writer”);

var MusicPieceCondition = PieceWriterModel.getConditionByName(“MMA_Music_PieceId”);

var PieceId = Piece.Id;

PieceWriterModel.setCondition(MusicPieceCondition,PieceId);

console.log(‘After Set condition’ + PieceId + ’ PieceId ‘);

PieceWriterModel.updateData(function(){

NoOfWriters = PieceWriterModel.data.length;

if(NoOfWriters>0){

for(i=0;i<NoOfWriters;i++){

if(PieceWriterModel.dataOi].MMA_Music_Composer__c){

MusicWriter = PieceWriterModel.dataPi].MMA_Music_Composer__r.Name;

HtmlString = HtmlString + ‘

’+ ‘&nbsp;’ + ‘&nbsp;’ + ‘&nbsp;’ + ‘&nbsp;’+ MusicWriter +’';

if(PieceWriterModel.data;i].MMA_Music_Writer_Role__r){

var MusicWriterRole = PieceWriterModel.data>i].MMA_Music_Writer_Role__r.Name;

var Writer_Role_String = ‘, ‘+ MusicWriterRole +’
’;

HtmlString = HtmlString + Writer_Role_String;


                    }
else{
}}
else{
window.alert(Piece_Name + ' - This Piece does not have any associated Music Writers.');
}
}
var cellElem = field.element;
cellElem.html(HtmlString);
}
});



}
else{
cell.Elem.html(HtmlString);
}

Can you explain what you mean by ‘stuck’? You mention a loop but I don’t see a for statement.

What do you see on the console? Are there any error messages? What are your console.log statements writing? Is the alert firing?

My initial suspicion is an empty field value that the model is actually including as undefined, but you are testing for an empty string with ‘’. The console should give an error message to that effect, however.


There is a for loop


     for(i=0;i<NoOfWriters;i++){
if(PieceWriterModel.data[i].MMA_Music_Composer__c){
MusicWriter = PieceWriterModel.data[i].MMA_Music_Composer__r.Name;
HtmlString = HtmlString + '<div><ul><em><font color="grey" size="3" style="font-family:Georgia">'+ '&amp;nbsp;' + '&amp;nbsp;' + '&amp;nbsp;' + '&amp;nbsp;'+ MusicWriter +'';

When the Snipet is rendering values, model is filtered for only last pieceid. But we want Snipet to filter the model based on the row value (piece id).


Once the model is filtered for the each row value, update function on the model should return the values based on the row value.

Currently the Snipet is returning values corresponding to only the last pieceid for all the rows


I was reading your original on my phone and missed the for( loops. Oops!
I still don’t understand ‘stuck.’ That suggests the snippet dies on or immediately after the first iteration, when i=0, or perhaps at i=1.
Are there any console messages when the snippet runs?
I am also looking at two if statements:

  •  if(PieceWriterModel.dataoi].MMA_Music_Composer__c)

  • if(PieceWriterModel.dataoi].MMA_Music_Writer_Role__r)

I am thinking these cannot both be correct, and I am thinking the relational indicator, __r, is not valid without a field reference. Should it be __c? They may both be right, but I’m not able to check easily at the moment.

The comment about “last pieceid  for all the rows” has me wondering if the snippet is being called through a custom renderer on a table column/field. Do you then see on every row in the table the expected snippet results from the last row displayed? What happens if you change the number of rows displayed? Do you also have a Search box or a Filter with which you can limit the number of rows to 1, or to a different data set; what happens then? Could you also add a console.log(HtmlString); immediately after the for loop terminates?



Reply