The purpose of this script is to populate an index of the current row by comparing the vertical position of the current row to the vertical position of an index of another item row
REFERENCES_INDEX = Item Line ID on which we want to base the values in vertical position
NUMERO_REFERENCES_INDEX = Item line index ID for vertical positions
TOTAL_ARTICLE_LIGNES_ARTICLES_INDEX = ID of the current line that gives an idea of the current position of our item line
var calculScore = function(pInfo){
if(pInfo == null || pInfo.value == null || pInfo.value.rectangle == null)
return -1;
return (pInfo.numPage*10000)+pInfo.value.rectangle.y1;
};
var articles = getArticleLines(pParameters, "REFERENCES_INDEX");
var ref = [];
for(var i=0;i<articles.length;i++){
var r = getIndexFromArticleLine(articles[i], "NUMERO_REFERENCES_INDEX");
ref.push({"info" : getTextFromIndexInfo(r), "score": calculScore(r)});
}
ref.sort(function(a, b){return b.score - a.score});
var currentArticle = getCurrentArticleLine(pParameters);
var calculCurrent = calculScore(getIndexFromArticleLine(currentArticle, "TOTAL_ARTICLE_LIGNES_ARTICLES_INDEX"));
var currentRef = "";
var j = 0;
while(j < ref.length && currentRef == ""){
if(calculCurrent >= ref[j].score)
currentRef = ref[j].info;
j = j + 1;
}
return currentRef;