Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to write a user script to return a unique ID

Allan Parsons February 15, 2018

I am new to confluence and user macros.

I have managed to create a simple user script as follows - 

## @noparams
$content.getIdAsString()

Which works fine and returns the page id.

However I want to extend the functionality here to only return the last x characters in the string.

How would I do this?

2 answers

2 accepted

0 votes
Answer accepted
Allan Parsons February 18, 2018

I tried the below and it gave me what I wanted.

## @noparams
$content.getIdAsString().substring(4)

 

Hopefully this helps somebody else also.

Thanks to Danyal for the tip.

0 votes
Answer accepted
Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 16, 2018

$content.getIdAsString().split()

#Velocity is just a façade for real Java objects, so you have access to all the public methods of the String class, including indexOf and substring.

Allan Parsons February 18, 2018

Hi,

Thanks for taking the time to respond.

I have no experience in Java, so am googling everything I am trying here (I found the code above after a bunch of googling also.)

Will also google this Velocity stuff and hopefully figure out how to manipulate the string to return what I want.

Any tips?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events