Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script Runner Behaviors wont load Insight objects for customers (works for licensed users)

Tomáš Vrabec May 15, 2020

Hello there.

One of my customer is using Script Runner Behaviors for dynamic forms and for prefilling data to various fields based on current user.

Mainly:

  1. The Current user is filled into custom field
  2. The Current user do have "shadow in Insight"
  3. One of the attributes in Insight is the user manager
  4. User manager is populated into another custom field

We dont know what exactly happened, code is little bit old, but right now customer figured out, that it wont work, if the user is logged in as the customer. 

I tried it, reproduce it with 100% success. As service desk or software or core user, everything works.

As customer, neither current user or manager and other fields are populated.

Any idea where it could be wrong? Probably happened with some Script Runner or Insight upgrade, but noone noticed for a while ...

 

import com.atlassian.jira.component.ComponentAccessor

// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the Requestor field
def requestor = getFieldById("customfield_10401")
if (requestor.formValue == "")
{
requestor.setFormValue(currentUser.key)
}

// change this to ID of schema, where IQL should search for objects
def schemaID = 3
// change this to name of field, where Phone number should be stored
def phoneField = getFieldByName("Contact number")
// change this to name of field, where Manager should be stored
def managerField = getFieldByName("Manager or supervisor (approver)")
// change this to name of attribute in Insight, where phone number is stored
String attributeManager = "User Manager"
// change this to name of attribute in Insight, where phone number is stored
String attributePhone = "Mobile Phone"
// change this to name of attribute in Insight, where user key is stored
String attributeUserID = "Employee ID"

if( getFieldById(getFieldChanged()).getValue() )
{
// Get Insight IQL Facade from plugin accessor
Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade")
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass)
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)

def userKey = getFieldById(getFieldChanged()).getValue().toString()
def objects = iqlFacade.findObjectsByIQLAndSchema(schemaID, "\"" + attributeUserID + "\" = \"" + userKey + "\"")

int objectId = objects[0].getId()

def objectPhone = objectFacade.loadObjectAttributeBean(objectId, attributePhone)
if( objectPhone )
{
def objectAttributeValues = objectPhone.getObjectAttributeValueBeans()
def objectAttributeValue = objectAttributeValues[0]
phoneField.setFormValue(objectAttributeValue.getValue())
}
else
{
phoneField.setFormValue(null)
}

def objectManager = objectFacade.loadObjectAttributeBean(objectId, attributeManager)
if( objectManager )
{
def objectAttributeValues = objectManager.getObjectAttributeValueBeans()
def objectAttributeValue = objectAttributeValues[0] // object ID
def objectManagerRef = objectFacade.loadObjectAttributeBean(objectAttributeValue.getValue(), attributeUserID)
if( objectManagerRef )
{
objectAttributeValues = objectManagerRef.getObjectAttributeValueBeans()
objectAttributeValue = objectAttributeValues[0]
managerField.setFormValue(objectAttributeValue.getValue())
}
else
{
managerField.setFormValue(null)
}
}
else
{
managerField.setFormValue(null)
}

}
else
{
phoneField.setFormValue(null)
managerField.setFormValue(null)
}

 Insight 8.4.3

Script Runner 5.9.1-p5

Jira Software 8.5.1

Jira Service Desk 4.5.1

Thanks for any ideas

2 answers

1 accepted

1 vote
Answer accepted
Tomáš Vrabec May 27, 2020

UPDATE:

With support we found out the the issue is caused most probably by documented bug at https://productsupport.adaptavist.com/browse/SRJIRA-3918

0 votes
Gyorgy Dani-Rauf May 26, 2020

Hi Tomas,

Did you check in the schema configuration in the roles section if if the Object Schema Users permissions for Service Desk Customers are enabled?

Br,
G

Tomáš Vrabec May 27, 2020

With support we found out the the issue is caused most probably by documented bug at https://productsupport.adaptavist.com/browse/SRJIRA-3918

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
4.5.1
TAGS
AUG Leaders

Atlassian Community Events