portfolioChildIssuesOf in Customfield as URL

We have an Automation, which creates a CustomField (URL) with the URL:

(https://mydomain.atlassian.net/issues/?jql=issue%20in%20portfolioChildIssuesOf(%22{{issue.key}}%22))

But the Automation Rule is breaching Automation Limits (More than 3600 seconds within 12 hours)

So I tried to set the URL by ScriptRunner.

But

def newCustomFieldValue = "https://mydomain.atlassian.net/issues/?jql=issue%20in%20portfolioChildIssuesOf(%22{{issue.key}}%22))"

causes errors

Specify a valid URL for the custom field

Here the non working script

// Specify all the required parameters
def projectKey = 'TEST'
def customFieldName = 'portfolioChildIssuesOf'
def newCustomFieldValue = "https://mydomain.atlassian.net/issues/?jql=issue%20in%20portfolioChildIssuesOf(%22{{issue.key}}%22))"

def customField = get("/rest/api/2/field")
    .asObject(List)
    .body
    .find {
        (it as Map).name == customFieldName
    } as Map
assert customField

def jqlQuery = "project = $projectKey and '${customFieldName}' is not EMPTY"

def result = get('/rest/api/2/search')
    .queryString('jql', jqlQuery)
    .header('Content-Type', 'application/json')
    .asObject(Map)

def issues = result.body.issues as List<Map>

issues.forEach { Map issue ->
    def fields = issue.fields as Map
    def customFieldValue = fields[customField.id]
    logger.info("Changing value ${customFieldValue} of custom field ${customFieldName} for issue ${issue.key}")

    def updateDoc = [fields: [
        (customField.id): newCustomFieldValue
    ]]

    // Now we make the change, ignoring whether the field exists on the edit screen
    def resp = put("/rest/api/2/issue/${issue.key}")
        .queryString("overrideScreenSecurity", true)
        .header("Content-Type", "application/json")
        .body(updateDoc)
        .asObject(Map)

    if (resp.status > 299) {
        logger.error("Failed to update ${issue.key}: ${resp.statusText} - ${resp.body}")
    } else {
        logger.info("Custom field ${customFieldName} changed to value ${newCustomFieldValue} for issue ${issue.key}")
    }
}

Hi.
I think the problem could be that you are using smart values in the URL and maybe is not supported as a custom field value. you try to replace {{issue.key}}with ${issue.key}

If this not work, Could you give us more details, for instance, the line that is failing and the logs that you see?

Thanks, Ivan.