/** This example script console script shows how to change the owner of a filter or dashboard . * Note this script should be run as the ScriptRunner add on user* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */// Note this script should be run as the ScriptRunner add on user// Enter the Id of the filter to update heredeffilterId='';// Enter the Id of the dashboard to update heredefdashboardId='';// Enter the accountId of the new owner heredefnewOwnerAccountId='';if(filterId.size()==0&&newOwnerAccountId.size()==0||dashboardId.size()==0&&newOwnerAccountId.size()==0){return"You must specify a filter id or dashboard I=id and the accountId for the new user to be able to change a filter or dashboards ownership";}if(filterId.size()>0){defupdateFilterOwner=put("/rest/api/3/filter/${filterId}/owner").header('Content-Type','application/json').body([accountId:newOwnerAccountId]).asString()assertupdateFilterOwner.status>=200&&updateFilterOwner.status<300logger.info("The filter with the Id: ${filterId} was updated to be owned by the user with the accountId of ${newOwnerAccountId}.")}if(dashboardId.size()>0){defupdateDashboardOwner=put('/rest/api/3/dashboard/bulk/edit').header('Content-Type','application/json').body([action:'changeOwner',changeOwnerDetails:[autofixName:false,newOwner:newOwnerAccountId],entityIds:[dashboardId.toInteger()],permissionDetails:[sharePermissions:[[user:[accountId:newOwnerAccountId,],id:dashboardId.toInteger(),type:"user"]]]]).asString()assertupdateDashboardOwner.status>=200&&updateDashboardOwner.status<300logger.info("The dashboard with the Id: ${dashboardId} was updated to be owned by the user with the accountId of ${newOwnerAccountId}.")}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.