Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Help with split/substring

Ben Hart May 24, 2024

So I have an auto rule that's sending a web request, the {{webResponse.body.data}} contains:

data={total=1, items=[{id=3186}]

 

I am trying to define variable {{DeviceID}} as '3186' however so far failing. Here's what I've tried the following smart values that are in an Add Comment task:


{{webResponse.body.data.items.split("=").substringBefore("}")}}
{{webResponse.body.data.items.split("=")}}
{{webResponse.body.data.items.split("=").last}}
{{webResponse.body.data.items.split("=").2}}{{webResponse.body.data.items.split("=").remove("{").remove("}")}}{{webResponse.body.data.items.split("=").remove("{}")}}

These are all attempts from what I can gleen through the various docs, and right now they all return null, nada, zilch.

{{webResponse.body.data.items}} returns {id=3186}

 

This looks like a shotgun approach but I was really trying to get less specific to find the cut off but it eludes me and at this point I'm lost.

1 answer

0 votes
Alexis Robert
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 24, 2024

Hi @Ben Hart , 

 

did you try using something like this : 

 

{{webResponse.body.data.items.substringAfter("id=").substringBefore("}")}}

 

I guess this would work better, let me know if it doesn't.

 

--Alexis

Ben Hart May 24, 2024

Trying it right now.  Curiously, why would it work better?

Ben Hart May 24, 2024

So, no dice. The log step still showed nothing for this value.  Now I gotta admit, I left off another two key=value pairs accidentally.  the legit, and full value of data is:

 

data={total=1, items=[{id=3186}], searchId=null, isMin=false}

 

The full body is:

 

{status=200, errmsg=OK, data={total=1, items=[{id=3186}], searchId=null, isMin=false}}

Ben Hart May 28, 2024

Experimenting further I've tried:

Log Action- second items : {{webResponse.body.data.items.substringAfter("items=[").substringBefore("}")}}

 

Which returns null. I did also try this without the `.substringBefore("}")}}` but it also flopped.

Ben Hart May 28, 2024

This is getting infuriating, so heres what I've got right now based on trying to further tweak `{id-1234}`:

 

1. log action: {{webResponse.body.data.items}}

this returns the value above {id=1234}

2. log action: {{webresponse.body.data.items.substringAfter("items=[{id=").substringBefore("}]")}}

logs nothing, empty.

3. log action: {{webResponse.body.data.items.match("(\b\d{3,4}\b)")}}

also nothing

4. log action: {{webResponse.body.data.substringAfter("items=[{id=").substringBefore("}]")}}

nothing as well.

 

 

Is there a better way to build these smart values? Like does this syntax adhere to Java, or some typical, normal language?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events