Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Comparing first letter of field to previous record in a repeater transformation View modes: 
User avatar
Member
Member
Tom - 9/13/2011 9:58:31 AM
   
Comparing first letter of field to previous record in a repeater transformation
We use the transformation below in a Repeater to display links to directions. We would like to add a space when the first letter of the LocationName is different than the first letter of the previous record.

Suggestions?

<%# IfCompare(Eval("LocationName"),"None","<a href=" + GetDocumentUrl()+ ">" + Eval("LocationName")+ "</a><br />","")%>

User avatar
Member
Member
kentico_michal - 9/14/2011 2:57:54 AM
   
RE:Comparing first letter of field to previous record in a repeater transformation
Hello,

Regrettably, it is not possible to access the previous displayed record. However, there is a simple work-around.

You can create a two methods setWord, getWord that would set and get the LocationName to the RequestStockHelper class so that you can access the LocationName of previous row.
    
public static string setWord(object input)
{
string word = ValidationHelper.GetString(input, String.Empty) ;
CMS.GlobalHelper.RequestStockHelper.Add("value", word);
return "";
}

public static string getWord()
{
string word = ValidationHelper.GetString(CMS.GlobalHelper.RequestStockHelper.GetItem("value"), String.Empty);
return word;
}


Third custom method would simply compare the current LocationName and the previous one (retrieved by the getWord method):

    
public static string compareStrings (object currentInput, object previousInput)
{
string currentWord = ValidationHelper.GetString(currentInput, "") ;
string previousWord = ValidationHelper.GetString(previousInput, "");

if ( !previousWord.Equals("") && !currentWord.Equals(""))
{
// check first letter of both variables and return currentWord with a space if necessary
}
return currentWord;
}


Then, your transformation could look like this one:

<%# MyFunctions.compareStrings( Eval("LocationName"), MyFunctions.getWord() ) %>

<%# MyFunctions.setWord( Eval("LocationName ") ) %>


For more information about custom transformation method, I would like to point you to the following article: Adding custom functions to transformations

Best regards,
Michal Legen

User avatar
Member
Member
Tom - 9/14/2011 6:06:23 AM
   
RE:Comparing first letter of field to previous record in a repeater transformation
Thanks very much for the very complete example, Michal. We will give that a try.

User avatar
Member
Member
Tom - 9/14/2011 6:11:33 AM
   
RE:Comparing first letter of field to previous record in a repeater transformation
Is there any way to add a Custom Function without accessing Visual Studio?

User avatar
Member
Member
kentico_michal - 9/14/2011 6:54:26 AM
   
RE:Comparing first letter of field to previous record in a repeater transformation
Hello Tom,

It is possible to edit the pertinent file also using standard text editor on the other hand it is not really a convenient way of doing it. However, it is up to you what approach suits you better.

Best regards,
Michal Legen