Forums

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

Automatically fill in organisation field based on user

Melle van Keulen
Contributor
September 10, 2021

Hi,

If an user creates a request from the portal, it automatically assigns the right organisation to the ticket. However, if an agent creates a ticket for the user, it doesn't automatically assign it. What is the best way to autofill the organizations field based on a user when an agent creates the ticket?

I can't seem to find the right automation rule for this, any suggestions for this issue?

Regards,
Melle van Keulen

1 answer

0 votes
said kouzibry
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.
September 10, 2021

It is best to use a post-function for this, set the organisation based on the reporter of the request instead of the creator.

Jack Brickey
Community Champion
September 10, 2021

How does that work? How does the reporter get associated to an organization. Which post Function are you using? Can you provide the details on this?

Like # people like this
said kouzibry
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.
September 10, 2021

My apologies, I should've have made my answer clearer, especially since it requires Script runner,

I did it in the past using a scripted post-function with a similar code to the following :

def issueKey = issue.key
def organizations=get('/rest/servicedeskapi/organization').asObject(Map).body.values
def foundOrg;
for(def org in organizations){
String id=org.id
id=id.replaceAll("\"", "")
def users=get('/rest/servicedeskapi/organization/'+id+'/user').asObject(Map).body.values

for(def user in users){
String accID=user.accountId
if(accID==issue.fields.reporter.accountId ){
foundOrg=org
break
}
}
if(foundOrg!=null){
break
}
}
def orgid=foundOrg.id.replaceAll("\"", "") as Integer
def result = put("/rest/api/2/issue/${issueKey}").header('Content-Type', 'application/json')
.body([
fields: [
customfield_10002 : [orgid]
]
])
.asString()

customfield_10002 here being the Organizations field,

it's not the cleanest/clearest code but it does the job.

Jacob Stensgaard
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 2, 2021

Fantastic @said kouzibry, just what I was looking for. My case is a bit different as Customers sometimes choose to set the SM request as private "Share with No One". In this case the Organization custom field will be empty. I need to update a Tempo Account field based on the Organization content. I think I can manage to tweak the script, however I do need somehow to be able to support pagination to the Organizations call  as we have more than 50 organizations. Do you know how to do that?

Much appreciated.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events