You need to sign in to do that
Don't have an account?
Scott Janis 20
I have this string that I need to parse out values using a formula field. I have working examples from values 1 , 2 and 3 but I can't see the pattern within these to extend to values 4 , 5 and 6 in the string. Would appreciate any kind of guidance even if its just breaking down the code so I can modify it that is , explaining what's happening.
Article | Onsite | Sponsorship | Editorial | TFK Kid of the year | Standard
Value 1
TRIM(LEFT(AB2__ABMediaElementPath__c , FIND("|", AB2__ABMediaElementPath__c )-1))
Value 2
LEFT(RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )), FIND("|" , RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )))-1)
Value three
LEFT(RIGHT(AB2__ABMediaElementPath__c , LEN(RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c ))) - FIND ("|", RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )))), FIND("|" , RIGHT(AB2__ABMediaElementPath__c , LEN(RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c ))) - FIND ("|", RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )))))-1)
USING LEN RIGHT LEFT etc......
I have this string that I need to parse out values using a formula field. I have working examples from values 1 , 2 and 3 but I can't see the pattern within these to extend to values 4 , 5 and 6 in the string. Would appreciate any kind of guidance even if its just breaking down the code so I can modify it that is , explaining what's happening.
Article | Onsite | Sponsorship | Editorial | TFK Kid of the year | Standard
Value 1
TRIM(LEFT(AB2__ABMediaElementPath__c , FIND("|", AB2__ABMediaElementPath__c )-1))
Value 2
LEFT(RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )), FIND("|" , RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )))-1)
Value three
LEFT(RIGHT(AB2__ABMediaElementPath__c , LEN(RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c ))) - FIND ("|", RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )))), FIND("|" , RIGHT(AB2__ABMediaElementPath__c , LEN(RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c ))) - FIND ("|", RIGHT(AB2__ABMediaElementPath__c , LEN(AB2__ABMediaElementPath__c ) - FIND ("|", AB2__ABMediaElementPath__c )))))-1)
The formula is repeating several different functions to get the specified value from between the pipes. Let me try to break down the functions and what each is doing using the first formula and “Article | Onsite | Sponsorship | Editorial | TFK Kid of the year | Standard” as the value in AB2__ABMediaElementPath__c
Value 1:
Now where the formula suddenly increases in size for the other values is because you can nest functions within other functions. The text or character position you find in one function, you can then set as a value in another function
To summarize what's happening in Value 2:
1. The LEFT() function wraps around all other functions
2-5 The RIGHT() function creates the text string that is passed as the first parameter to the LEFT() function. Remember this takes a text value and then a number of characters to return
3. The RIGHT() function is passed the entire field value
4. The number of characters to return for the RIGHT() function. It is LEN (the length) of the entire field value MINUS the position of the first pipe. The FIND() function is passed a pipe to find in the field and it returns the position of the first one it finds. From the first Value we know the pipe is at position 9. The length of the entire string is 75 characters, minus 9 is 66. So this function is returning the first 66 characters of the string starting from the RIGHT. What this creates is the text value "Onsite | Sponsorship | Editorial | TFK Kid of the year | Standard"
5. Closes out this RIGHT() function.
7-10. This is basically identical to the previous section, except it's wrapping it all in the FIND() function to find the first pipe in the new text string that gets created.
In summary, the first part starts with
Article | Onsite | Sponsorship | Editorial | TFK Kid of the year | Standard
and generates
Onsite | Sponsorship | Editorial | TFK Kid of the year | Standard
The second part finds the position of the first pipe (just like we saw in Value 1). This is all passed to the LEFT() function and as a result it shows "Onsite".
The subsequent formulas just need to repeat this process in a nested format to find the subsequent pipes and return the correct number of characters.
I hope you see this and that it makes sense.
Formula:
LEFT(RIGHT(Current_Value__c, LEN(RIGHT(Current_Value__c, LEN(Current_Value__c) - FIND ("|", Current_Value__c))) - FIND ("|", RIGHT(Current_Value__c, LEN(Current_Value__c) - FIND ("|", Current_Value__c)))), FIND("|" , RIGHT(Current_Value__c, LEN(RIGHT(Current_Value__c, LEN(Current_Value__c) - FIND ("|", Current_Value__c))) - FIND ("|", RIGHT(Current_Value__c, LEN(Current_Value__c) - FIND ("|", Current_Value__c)))))-1)
Sample 1 (works)
null|Department Head|10-2020|null-null|Government|null|null|null|false
Sample 2 (doesn't work)
null|MO|US