# portfolioChildIssuesOf in Customfield as URL

**URL:** https://forum.library.adaptavist.com/t/portfoliochildissuesof-in-customfield-as-url/342
**Category:** Scripts
**Tags:** jira, cloud
**Created:** [July 15, 2023, 2:29pm UTC](https://forum.library.adaptavist.com/t/portfoliochildissuesof-in-customfield-as-url/342 "2023-07-15T14:29:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alexander\_J](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Alexander\_J](https://forum.library.adaptavist.com/u/Alexander_J)
#### Post date: [July 15, 2023, 2:29pm UTC](https://forum.library.adaptavist.com/t/portfoliochildissuesof-in-customfield-as-url/342/1 "2023-07-15T14:29:01Z")

</div>

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

```auto
(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.

> **[Bulk Update the Value of a Custom Field on Jira Cloud Issues - Adaptavist...](https://library.adaptavist.com/entity/update-cf-values-all-issues-cloud?tab=cloud)**
>
> \####Overview
> Use this script in the \*Script Console\* to update the value of a custom text field for all issues returned by a query.
> 
> \####Example
> I have a project with many issues. I need to change the custom field value for all the issues in this...

But

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

```

causes errors

```auto
Specify a valid URL for the custom field

```

Here the non working script

```auto
// 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}")
    }
}

```

---

<div class="post-metadata">

### Author: ![imadero](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.library.adaptavist.com/imadero/32/59_2.png) [@imadero](https://forum.library.adaptavist.com/u/imadero)
#### Post date: [July 18, 2023, 7:25am UTC](https://forum.library.adaptavist.com/t/portfoliochildissuesof-in-customfield-as-url/342/2 "2023-07-18T07:25:59Z")

</div>

> [@Alexander\_J](#):
>
> `newCustomFieldValue`

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex019/uploads/adaptavistlibrary/original/1X/ceb18adf14fa58b4c6de03aa69ada8b07359620c.png) [@system](https://forum.library.adaptavist.com/u/system)
#### Post date: [January 14, 2024, 7:26am UTC](https://forum.library.adaptavist.com/t/portfoliochildissuesof-in-customfield-as-url/342/3 "2024-01-14T07:26:23Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
