[Ri...] Posted April 16 Share Posted April 16 Hello, I have a very simple code where I am pulling one piece of header information to set another piece of header information. customer=getRecordHead("u_{2267/1912}") setRecordHead("u_{1903}",customer) Works great, super simple. The issue is that sometimes there are pieces of information in the source that it is pulling from that I'd like to remove, without having to remove it from the source itself. Since it is pulling information from a customer name, the customer name may include things like ", Inc.", or ", LLC". Right now I just wrote a simple if statement to look for a specific customer name that does include the information that I don't want. customer=getRecordHead("u_{2267/1912}") if customer=="Redacted, Inc." then customer="Redacted" else customer=getRecordHead("u_{2267/1912}") endif setRecordHead("u_{1903}",customer) My goal is to not have to write a lot of "if or" statements, and I really do not want to change the source data. So is there a way to have it look for specific phrases and remove those if it sees them? And I was finally going to get some PCM training earlier this year, but I had to cancel due to other conflicts. 🙁 Stinks. Any and all help is greatly appreciated. Link to comment Share on other sites More sharing options...
[Ke...] Posted April 16 Share Posted April 16 I don't know if this will quite accomplish what you are after, but maybe you can adapt some of the tools in viewtopic.php?p=56768#p56768 Link to comment Share on other sites More sharing options...
[An...] Posted April 16 Share Posted April 16 Not sure this specific application would be shown at a PCM course... But I haven't taken one, so I wouldn't know! 🤣 Definitely a more codey solution than a PCM parameterization of an inspection plan. A summary of the following: Uses inStr to find a substring within a string, then a mix of subStr and mid to remove the substring Loops to remove any instance of the strings in the list "NOT_ALLOWED_LIST" until none remain Limited by how exhaustive the "NOT_ALLOWED_LIST" is, edit as needed "NOT_ALLOWED_LIST" is case sensitive Very brute force, not very clever Examples: NOT_ALLOWED_LIST = list(", Inc.", "ABC", "_____", ", L. L. C.") Ex: Redacted, Inc. → Redacted Ex: Redacted, LLC → Redacted, LLC Ex: Redacted, inc. → Redacted, inc. (case sensitive) Ex: Just ABC, Inc._____Do It → Just Do It Ex: [color=#FF0000]ABCABCABC_____[/color]LLC[color=#FF0000]_____[/color]_→ LLC_ // Edit this list with what you don't want NOT_ALLOWED_LIST = list(", Inc.", ", LLC", ", Inc", ", LLC.") NOT_ALLOWED_LIST_NAME = "NOT_ALLOWED_LIST" customer = getRecordHead("u_{2267/1912}") // Begin searching for not-allowed strings for not_allowed_index = 1 to NOT_ALLOWED_LIST.size repeat // Get the first not-allowed string to check this_not_allowed_str = getParameterNamed(NOT_ALLOWED_LIST_NAME, not_allowed_index) this_not_allowed_len = len(this_not_allowed_str) // Attempt to find the not-allowed string // - if found, will be non-zero // - if not found, will be zero attempt = inStr(customer, this_not_allowed_str) // If the not allowed string was found, // - from: the start of the original string (1) // - to: the attempt index (minus 1 to not include the 1st character) // - PLUS // - from: attempt index + the length of the search string // - to: the end of what remains if attempt <> 0 then customer = subStr(customer, 1, attempt - 1) + mid(customer, attempt + this_not_allowed_len) endif until attempt == 0 // repeat for all not-allowed strings next not_allowed_index // Output setRecordHead("u_{1903}", customer) A more "general use" version that could be modified to anyone's liking, if needed: // Edit this list with what you don't want NOT_ALLOWED_LIST = list("ABC", "123", "FOO", ".pdf") NOT_ALLOWED_LIST_NAME = "NOT_ALLOWED_LIST" source_string = inquireText("Enter something to be filtered:") // Begin searching for not-allowed strings for not_allowed_index = 1 to NOT_ALLOWED_LIST.size repeat // Get the first not-allowed string to check this_not_allowed_str = getParameterNamed(NOT_ALLOWED_LIST_NAME, not_allowed_index) this_not_allowed_len = len(this_not_allowed_str) // Attempt to find the not-allowed string // - if found, will be non-zero // - if not found, will be zero attempt = inStr(source_string, this_not_allowed_str) // If the not allowed string was found, // - from: the start of the original string (1) // - to: the attempt index (minus 1 to not include the 1st character) // - PLUS // - from: attempt index + the length of the search string // - to: the end of what remains if attempt <> 0 then source_string = subStr(source_string, 1, attempt - 1) + mid(source_string, attempt + this_not_allowed_len) endif until attempt == 0 // repeat for all not-allowed strings next not_allowed_index // Output display(source_string) Slight tangent: the built-in Calypso description/documentation for [color=#0000FF]inStr[/color] has the inputs backwards! The PDF documentation has it right: [color=#0000FF]inStr[/color]([start_index,] source_to_search, target_to_find) I'm also sure there's an [color=#0000FF]executeCode[/color] version of this that is more robust, but no guarantees on [color=#0000FF]executeCode[/color] sticking around long-term. 😭 Hope this works!general.txtcustomer.txt Link to comment Share on other sites More sharing options...
[Ri...] Posted April 17 Author Share Posted April 17 Thank you, thank you, thank you, thank you so very much! I was not expecting someone to do all of the legwork for me, but I greatly appreciate it so very much. If I can tip you or something to help compensate you for your time I will be glad to do so. Thank you once again. This works beautifully and does exactly what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in