Error when put variables in function REPLACE()

Alexandra DM
Contributor
October 21, 2024

Hi, I'm trying to replicate  a simple test where I've created different variables to replace the content of div (html)

Variables

baseContent =

 <div id="content"> <p>This is the original content</p> <!--PLACEHOLDER--> </div>

valueReplace = 
<!--PLACEHOLDER-->

replaceContent =
<p>NEW CONTENT</p>

It only runs correctly when placed directly with values set in the double quotes combinedContent = {{baseContent.replace("PLACEHOLDER","W")}}

But when I want to pass the replaceContent  and/or valueReplace variable it doesn't appear in any of the following tests

{{baseContent.replace("<!--PLACEHOLDER-->", replaceContent)}} -error {{baseContent.replace("<!--PLACEHOLDER-->","${replaceContent}")}} -error {{baseContent.replace(\{\{valueReplace\}\},\{\{replaceContent\}\})}} -- error {{baseContent.replace("{{valueReplace}}","{{replaceContent}}")}} -error {{baseContent.replace({{valueReplace}},{{replaceContent}})}} -error {{baseContent.replace($(valueReplace),$(replaceContent) )}} -error

 What is the correct way to pass smart values to a replace ? It's Jira Automation Data Center

test_replace.png

2 answers

1 vote
Bill Sheboy
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.
December 7, 2024

Hi @Alexandra DM 

I found an open defect for this symptom: https://jira.atlassian.com/browse/JIRAAUTOSERVER-975

It suggests a workaround to add trim() after the variable to force the type to text for the function parameter.  Perhaps try that as:

{{baseContent.replace("<!--PLACEHOLDER-->", replaceContent.trim())}}

 

As an aside, this defect implies the Create Variable action for Jira Data Center automation is not returning a "string" (i.e., text type), which is both different from Jira Cloud and does not match the Server / Data Center documentation:

https://confluence.atlassian.com/automation/jira-automation-actions-993924834.html#Jiraautomationactions-create-variableCreatevariable

 

Kind regards,
Bill

0 votes
Kseniia Trushnikova
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2024

Hey @Alexandra DM,

This would work in Jira Cloud:

{{baseContent.replace(valueReplace,replaceContent)}}

But the same function doesn't work in Jira DC... Perhaps, nested smart values aren't a thing in Data Center yet.

Suggest an answer

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

Atlassian Community Events