Problem with simple SUBSTRING / INDEX_OF

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

rest_reply.png
rest_reply.png (214.82 KiB) Viewed 5451 times
Since BOTH PARSE_JSON and the INDEX_OF have failed, I think the issue is because the record hasn't been committed yet.
But I also put a COMMIT TRANS in before the last BLUE statement in the image and nothing changed.

Very odd.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

rest_reply2.png
rest_reply2.png (233.41 KiB) Viewed 5437 times
Last edited by Jaymer on Tue Feb 15, 2022 4:25 pm, edited 1 time in total.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

If I wasn't seeing my reply in the LOG2 output, then I'd think maybe I did this wrong.
But I've created a new Reply record (so its in context), and this is set to write the reply into that BO and field.
Which it appears that it does... its just buggy that I can't do anything WITH that data.
rest_reply3.png
rest_reply3.png (141.78 KiB) Viewed 5438 times
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

Tried again using a long SessionVar field as the place to store the REST reply (instead of a new in-context record).

Prints fine, but same thing. Value seems inaccessible to other functions.
rest_reply4.png
rest_reply4.png (99.64 KiB) Viewed 5430 times
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
KnightWare
Posts: 139
Joined: Sat Feb 10, 2018 12:56 am

Re: Problem with simple SUBSTRING / INDEX_OF

Post by KnightWare »

Not sure if it's relatable, but I'm about to open another (same) topic. I can't get SUBSTRING/INDEX_OF to work on a calculated field in a query. A query on BO "AE" has a plain text field called "MaangementLevel", that's front padded with junk. I'm simply trying to display the right of the text. There are no blank (NULL) data fields.

example
AE.ManagementLevel = "85c1595f23261099073f776378263290MANAGEMENT_LEVEL_Team_Member"

SUBSTRING( AE.ManagementLevel, INDEX_OF('LEVEL_' , AE.ManagementLevel) +6, LENGTH(AE.ManagementLevel))
SUBSTRING( AE.ManagementLevel , 50 , LENGTH(AE.ManagementLevel))
SUBSTRING( AE.ManagementLevel , 0 , 20)

All return invalid calculation.
Driving me nuts.
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

This should work… unless 0 is not a valid starting index. Maybe try 1 in the 3rd

Certainly the 2nd should work.
As I did, maybe LOG2 the length function to see what it thinks.

I’m sure Vlad Will say something like “this code has not changed in ages so it’s not the aware code “ but chalk this up to more hours wasted. I didn’t want to sound like I was whining, but I had easily more than an hour in mine trying to figure it out.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
KnightWare
Posts: 139
Joined: Sat Feb 10, 2018 12:56 am

Re: Problem with simple SUBSTRING / INDEX_OF

Post by KnightWare »

No, none of them work. All same error "Invalid Calculation". This is on a calculated column in a query which this is the first I've tried.
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

Maybe it’s the java way of doing things, but I have NEVER liked the way the substring function needs two indices to work, rather than a starting location and a length.
If Vlad is reading this and he happens to go into the code,
Sure would be nice to create a new SUBSTRING2 function with the syntax:
SUBSTRING2 ( string, starting-pos, length )
And the Java function was smart enough to not crap out if the length exceeded the actually field length.
And It would accept a negative value to remove characters from the right trimmed end.

Extracting the value in the parens here is overly complex.
TheString = ‘jaymer jaymer (jj)’
Initials = substring( TheString, index( TheString, ‘(‘ ) + 1 , index( TheString, ‘)‘ ) )
Using “-1” here would use remaining string minus 1 character

TheString = ‘widget - item1234’
partnum = substring( TheString, index( TheString, ‘-‘ ) + 2 , length( trim(TheString)) )
(Omitting length here would go to end of string)

One thing about JavaScript libraries or newer languages (GO as an example, but it’s not necessarily “New”) is they streamline functions for us. This substring was coded over 10 years ago and hasn’t improved. We know Vlad can do things like this USUALLY, but not limited to, when he needs a function in his own projects or an improvement in aware (like output to “same panel” was needed to handle the input controls in a toolbar). And he recently added JSON_PATH which was nice.
Last edited by Jaymer on Wed Feb 23, 2022 7:18 pm, edited 1 time in total.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Problem with simple SUBSTRING / INDEX_OF

Post by Jaymer »

KnightWare wrote: Tue Feb 22, 2022 7:20 pm No, none of them work. All same error "Invalid Calculation". This is on a calculated column in a query which this is the first I've tried.
Oh, wish you just said that first.
Calculated columns are mostly crap in my opinion
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
KnightWare
Posts: 139
Joined: Sat Feb 10, 2018 12:56 am

Re: Problem with simple SUBSTRING / INDEX_OF

Post by KnightWare »

Maybe so, but I don't want to display all the junk in front of the value at right end of the string. Data is external source MSSQL. I'm now looking at doing it in a new MSSQL View.

But I shouldn't have to.
ACDC
Posts: 1138
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: Problem with simple SUBSTRING / INDEX_OF

Post by ACDC »

You could do : REPLACE PATTERN (strip out the _) and WORDS_FROM_RIGHT , its a work around :)

one of my use examples:
Audiogram.Time=WORDS_FROM_RIGHT(REPLACE_PATTERN(Audiogram.Date_Time_of_meassure,'_',' '),1)
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Problem with simple SUBSTRING / INDEX_OF

Post by BobK »

ACDC wrote: Wed Feb 23, 2022 9:31 am You could do : REPLACE PATTERN (strip out the _) and WORDS_FROM_RIGHT , its a work around :)

one of my use examples:
Audiogram.Time=WORDS_FROM_RIGHT(REPLACE_PATTERN(Audiogram.Date_Time_of_meassure,'_',' '),1)
I also thought of this, but no joy. It does not work in a calculated column of a query.
Bob
Post Reply