Formula for getting the profile prefix for templates and reports
Question:
How to separate the profile prefix (letters from the beginning of the PROFILE field) from the numeric values in templates and reports? It should return, for example, "TUBE" from the profile "TUBE500*10", and "PLATE" from the profile "PLATE200*10". Our formula does not work and another formula we tried is too long for the Template Editor formula field.
Answer:
This is one way to solve the issue. In this formula 8 characters from the beginning of PROFILE field are tested one by one whether they are numbers and if they are not, then they are output.if match(mid(GetValue("PROFILE"),0,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,0) elseif match(mid(GetValue("PROFILE"),1,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,1) elseif match(mid(GetValue("PROFILE"),2,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,2) elseif match(mid(GetValue("PROFILE"),3,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,3) elseif match(mid(GetValue("PROFILE"),4,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,4) elseif match(mid(GetValue("PROFILE"),5,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,5) elseif match(mid(GetValue("PROFILE"),6,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,6) elseif match(mid(GetValue("PROFILE"),7,1),"[0123456789]") thenmid(GetValue("PROFILE"),0,7) elsemid(GetValue("PROFILE"),0,8)endif endif endif endif endif endif endif endif
This is another option to solve the issue. This formula finds the smallest position of numbers in the profile string using the min() function and then returns the characters from the beginning of the string using the mid() function. This formula also shows how you can use GetFieldFormula() to work around the length limit in the formula field. The long formula is divided into several separate fields.
mid(GetValue("PROFILE"),0,min(GetFieldFormula("Find0"),GetFieldFormula("Find1"),GetFieldFormula("Find2"),GetFieldFormula("Find3"),GetFieldFormula("Find4"),GetFieldFormula("Find5"),GetFieldFormula("Find6"),GetFieldFormula("Find7"),GetFieldFormula("Find8"),GetFieldFormula("Find9")))
In addition to this field, you need 10 separate and hidden value fields for calculating the position of numeric characters in the profile string.
The value field Find0 contains this formula:
if find(GetValue("PROFILE"),"0") == -1 then 99 else find(GetValue("PROFILE"),"0") endif
This formula searches the position of zero in the profile string. If it does not find zero, it outputs 99, if it finds zero in the profile string, then the formula outputs the position of the zero. You have to remember that positions starts from zero, so the position of first character is 0 and not 1.
Find1 contains this formula:if find(GetValue("PROFILE"),"1") == -1 then 99 else find(GetValue("PROFILE"),"1") endif
This formula searches the position of number 1 in the profile string.
Other Find fields are defined in the same way.