Sync insight customfields

Originally asked by Patrick Mennecke on 12 February 2021 (original question)


How can i send object attributes for example name?

With this https://docs.idalko.com/exalate/display/ED/How+to+sync+Insight+custom+fields i only send the id.


Answer by Jonathon Irwin on 22 February 2021

The method I’ve used for some time (probably not the most elegant) is below:

final def insightCustomFieldName = "nameOfInsightField"
def insightKey = issue.customFields[insightCustomFieldName]?.value?.collect{
		v ->
		def cfm = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager()
		def cf = cfm.getCustomFieldObject(issue.customFields[insightCustomFieldName].id)
		def cft = cf.getCustomFieldType()
		def vStr = cft.getStringFromSingularObject(v)
		vStr
	}
if (insightKey != null) {
	insightKey = insightKey[0]
} else {
	return
}
def objectSchemaId = 3 // This is the objectSchema you'll be searching for values (can be seen in URL when viewing schemas in Insight)
Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade");
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass);
/* Load objects with a specific value for a specified attribute */
def IQL = 'Key = "'+insightKey+'" AND objectType = Users'
int attributeRef= 499 // this is the ID of the attribute you want from the object selected in the field.
def insightObject = iqlFacade.findObjectsByIQLAndSchema(objectSchemaId,IQL)
/* If this is a mandatory field you should be able to do this: */
if (insightObject != []) {
	for (temp in insightObject [0].getObjectAttributeBeans()) {
		if (temp.getObjectTypeAttributeId().equals(attributeRef)) {
			replica.customKeys."SomeKey" = temp.getObjectAttributeValueBeans()[0].getTextValue()
		} 
	}
}

I think I’ve also used a way to search using attribute names but don’t have that code on-hand.


Comments:

Patrick Mennecke commented on 24 February 2021

Thanks, that works.

Answer by Ariel Aguilar on 16 February 2021

Hi Patrick,

It would be helpful if you can try sending a sync from side A to side B, then checking the Entity Sync Status on side B and looking at the “remote replica”? Here you can see how the Insight field is being sent, feel free to post it on this thread.

Best regards,

Ariel


Comments:

Patrick Mennecke commented on 16 February 2021

That is the ougoing rule

final def insightCustomFieldName = "IBM Server"
  
replica.customKeys.
"IBM Server" = issue.customFields"IBM Server"?.value?.collect{
v ->
  def cfm = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager()
def cf = cfm.getCustomFieldObject(issue.customFields[insightCustomFieldName].id)
def cft = cf.getCustomFieldType()
def vStr = cft.getStringFromSingularObject(v)
vStr
}


with that i only send the Insight ID for example: CMDB-1027

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