cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mikekiser
Helper I
Helper I

At wits end with Logic App Substring - PLEASE HELP

Hi 

We have some addresses that are greater than 30 chars and I have to truncate those to 30 chars max.....what I am trying to do is

 

"Condition_2": {
                                "actions": {
                                    "Set_variable": {
                                        "inputs": {
                                            "name""Address",
                                            "value""@{substring(body('Parse_JSON_2')?['address1'],0,29)}"
                                        },
                                        "runAfter": {},
                                        "type""SetVariable"
                                    }
 
The error I am getting is: PLEASE HELP! Thanks Mike Kiser
Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '2956': 'The template language function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string
9 REPLIES 9
Jcook
Super User III
Super User III

Hello @mikekiser 

 

Have you tried to use the substring action? For complex subscribe expressions, it can be very useful.


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Jcook
Super User III
Super User III

@mikekiser  Here is a blog on the substring action:

https://flowaltdelete.ca/2020/07/14/power-automate-substring-and-text-positions-made-easy/


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Thanks. I did try the SubString but must have been doing something wrong. I'll read the blog; thanks for your post!
Mike

Hi,

I am trying to use this after reading the blog but I am getting a syntax error

 

substring(variables(Address),0,9)
 
 
It looks good to me; any ideas?
Thanks
Mike

@mikekiser 

 

Try changing to:

substring(variables(Address),1,9)

 

I dont think substring() uses array indexes.


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Thanks for your response but it still failed

 

error:

InvalidTemplate. Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '2956': 'The template language function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'.

 

code:

"Condition_2": {
                                "actions": {
                                    "Set_variable": {
                                        "inputs": {
                                            "name""Address",
                                            "value""@{substring(body('Parse_JSON_2')?['address1'],1,29)}"
                                        },
                                        "runAfter": {},
                                        "type""SetVariable"
                                    }
                                },

@mikekiser  In the run of that error. Could you share the parse json2 address1 property value.

 

I want to confirm what is in the address1 property.


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Hello @mikekiser 

You are getting this error if the string you're trying to substring is too short.

Try adding a condition to check for this before doing the conversion

Please take a look at my POC:

 

Keep in mind I am using lots of Compose actions to show what is happening. You can use less for your solution

 

First I get the length of address1

Than I use a IF condition to check if address1 is greater than 30 chars

Jcook_0-1596247991095.png

 

If True:

Use the substring() expression on address1 

my expression is:

substring(outputs('Compose_-_address1'),0,30)

Jcook_1-1596248207107.png

 

If False:

Do nothing

 

Run:

with address1= This Address is too short

Jcook_2-1596248386121.png

 

Run:

With address1 = This Address is too long and will be trunked

Jcook_3-1596248480598.png

 


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Jcook
Super User III
Super User III

Hello @mikekiser 

 

Did you have a chance to try my solution?


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (38,242)