Item Index: Distribute a Material Code to All Lines

Principle:

Use this script to retrieve the detected value from a single item line (the 1st in a set) and apply this value to subsequent item lines.

This script requires 2 indexes:

  • index “value” which is an index detected on the document for certain item lines.
  • Index script that takes the value of the “value” index if it is detected, otherwise, the 1st non-empty value of “value” from the previous article rows

Script:

var getIndexValue = function(pParameters){
    var articles = getArticleLines(pParameters, "ARTICLES_INDEX");
    var currentArticle = getCurrentArticleLine(pParameters);
    if(articles == null || currentArticle == null)
    	return "";
    var indexValue = getTextFromIndexInfo(getIndexFromArticleLine(currentArticle, "VALUE_ARTICLES_INDEX"));
    if(indexValue != null && indexValue != "")
    	return indexValue;
    for(var i=currentArticle.idUnit - 1;i>= 0; i--){
    	var prevIndexValue = getTextFromIndexInfo(getIndexFromArticleLine(articles[i], "VALUE_ARTICLES_INDEX"));
    	if(prevIndexValue != null && prevIndexValue != "")
    		return prevIndexValue;
    }
    return "";
};
return getIndexValue(pParameters);