cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Community Champion
Community Champion

More OData help - simple left() right() text parsing routines.

This is so easy in excel... why the h these guys use this odata garbage, I will never know... but I am trying to do something very simple, in thought.  Can someone help me write the odata routine that I can put into a Set Variable action?

 

Column: Filename = 123456-r1.pdf

 

I need to set two variables from this same basic filename structure.

 

Variable: PartNumber

Variable: Revision

 

Partnumber = 123456 (all of the numbers up to and not including the "-")

 

Revision = 1 (the one or two digit number between the "r" and the ".")

 

In excel, I would write:

(A1)=123456R-r5.pdf

(A2)=SEARCH(".pdf",A1) = 11

(A3)=SEARCH("r",A1,A2-3) = 9

PartNumber=LEFT(A1,A3-2) = 123456R

Revision = MID(A1,A3+1,A2-A3-1) = 5

 

It would likely take me two full days to figure out all of the syntax required to do this simple task.  I beg for help from anyone that has some sympathy for my plight!

 

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
martinav
Community Champion
Community Champion

Ok, it took a bit less time than I expected.  Lucky this time.  Forunately, expression builder is more advanced than I thought.  It is still cryptic as hell.  I was blown away by the inability to do simple add/sub.  Had to wrap add() or sub() around things to do that.  wow...  What saved me wsa the lastIndexOf function.  The ability to search form the right made it much easier.

 

To find the last "r", I used Set Variabe "Find-r":  

lastIndexOf(body('Get_file_metadata')?['Name'],'r')

 

 To find the last ".", I used Set Variable "Find Dot":  

lastIndexOf(body('Get_file_metadata')?['Name'],'.')

 

To get part number, I wrote: 

substring(body('Get_file_metadata')?['Name'],0,add(variables('Find-r'),-1))

 

Toi get the revision number, I wrote: 

substring(body('Get_file_metadata')?['Name'],add(variables('Find-r'),1),sub(sub(lastIndexOf(body('Get_file_metadata')?['Name'],'.'),lastIndexOf(body('Get_file_metadata')?['Name'],'r')),1))

 

View solution in original post

2 REPLIES 2
martinav
Community Champion
Community Champion

Ok, it took a bit less time than I expected.  Lucky this time.  Forunately, expression builder is more advanced than I thought.  It is still cryptic as hell.  I was blown away by the inability to do simple add/sub.  Had to wrap add() or sub() around things to do that.  wow...  What saved me wsa the lastIndexOf function.  The ability to search form the right made it much easier.

 

To find the last "r", I used Set Variabe "Find-r":  

lastIndexOf(body('Get_file_metadata')?['Name'],'r')

 

 To find the last ".", I used Set Variable "Find Dot":  

lastIndexOf(body('Get_file_metadata')?['Name'],'.')

 

To get part number, I wrote: 

substring(body('Get_file_metadata')?['Name'],0,add(variables('Find-r'),-1))

 

Toi get the revision number, I wrote: 

substring(body('Get_file_metadata')?['Name'],add(variables('Find-r'),1),sub(sub(lastIndexOf(body('Get_file_metadata')?['Name'],'.'),lastIndexOf(body('Get_file_metadata')?['Name'],'r')),1))

 

View solution in original post

martinav
Community Champion
Community Champion

Nice solution... thank me very much!! 😄

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (2,753)