I have a HTML description field in SNOW called u_htm_desription
I want to send rich text and inline images from there to ADO description field.
I have a HTML description field in SNOW called u_htm_desription
I want to send rich text and inline images from there to ADO description field.
Hi and welcome to the Exalate Community!
Thanks for sharing your question or insight, we appreciate your contribution.
A member of the Exalate team or community will review this post and respond as soon as possible.
In the meantime, feel free to explore related topics or join other conversations. We’re glad to have you here!
Hi @Majid
Here is the script for ADO incoming:
import java.util.regex.Matcher
import java.util.regex.Pattern
if(firstSync){
workItem.projectKey = "Demo_Agile"
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Task";
}
workItem.summary = replica.summary
//workItem.description = replica.description
workItem.attachments = attachmentHelper.mergeAttachments(workItem, replica)
workItem.comments = commentHelper.mergeComments(workItem, replica)
workItem.labels = replica.labels
workItem.priority = replica.priority
if(firstSync){
store(issue)
}
def u_html_1 = replica.u_html_1
def replica_attachments = replica.attachments
def workitem_attachments = workItem.attachments
// this can be further enhanced to fetch tracker url and project id
def ado_org_url = "https://dev.azure.com/demoorgexalate/2f90a3a2-215a-4b9f-a5a7-d70a2f565ca0"
def sysIdToFilename = replica_attachments.collectEntries { [(it.remoteIdStr): it.filename] }
def filenameToAdoId = workitem_attachments.collectEntries { [(it.filename): it.idStr] }
def pattern = /src="\/sys_attachment.do\?sys_id=([^"]+)"/
def convertedHtml = u_html_1.replaceAll(pattern) { fullMatch, sysId ->
def filename = sysIdToFilename[sysId]
if (filename) {
def adoId = filenameToAdoId[filename]
if (adoId) {
return "src=\"${ado_org_url}/_apis/wit/attachments/${adoId}?fileName=${filename}\""
}
}
return fullMatch
}
workItem.description =convertedHtml
I will update tomorrow , how to fetch tracker url and project id dynamically
Hi @Majid
ServiceNow Outgoing Sync Script:
replica.u_html_1 = entity.u_html_1
ADO Incoming sync script:
import java.util.regex.Matcher
import java.util.regex.Pattern
if(firstSync){
workItem.projectKey = "Demo_Agile"
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Task";
}
workItem.summary = replica.summary
//workItem.description = replica.description
workItem.attachments = attachmentHelper.mergeAttachments(workItem, replica)
workItem.comments = commentHelper.mergeComments(workItem, replica)
workItem.labels = replica.labels
workItem.priority = replica.priority
store(issue)
def u_html_1 = replica.u_html_1
def replica_attachments = replica.attachments
def workitem_attachments = workItem.attachments
def await = { f -> scala.concurrent.Await$.MODULE$.result(f, scala.concurrent.duration.Duration$.MODULE$.Inf()) }
def orNull = { scala.Option<?> opt -> opt.isDefined() ? opt.get() : null }
def gsOptFuture = nodeHelper.azureClient.generalSettingsService.get()
def gs = orNull(await(gsOptFuture))
def trackerUrl = gs.issueTrackerUrl
def ado_org_url = trackerUrl+"/"+workItem.project.idStr
def sysIdToFilename = replica_attachments.collectEntries { [(it.remoteIdStr): it.filename] }
def filenameToAdoId = workitem_attachments.collectEntries { [(it.filename): it.idStr] }
def pattern = /src="\/sys_attachment.do\?sys_id=([^"]+)"/
def convertedHtml = u_html_1.replaceAll(pattern) { fullMatch, sysId ->
def filename = sysIdToFilename[sysId]
if (filename) {
def adoId = filenameToAdoId[filename]
if (adoId) {
return "src=\"${ado_org_url}/_apis/wit/attachments/${adoId}?fileName=${filename}\""
}
}
return fullMatch
}
workItem.description =convertedHtml
Hello,
Attachements do get created but at ticket creation it fails
there arent any errors, but i think the sysurl substitution does not work correctly because when i see the imaghe url in mardown it shows soemthing like this /sys_attachment.do?sys_id=5370cb5dc354321025df9aca0501312b
Can you also share the firstSync block of code from the ADO side please?
I ask as it might simply be a matter of arranging the store() call appropriately.
Thanks
Majid
import java.util.regex.Matcher
import java.util.regex.Pattern
if(firstSync){
// Set type name from source entity, if not found set a default
workItem.projectKey = “ServiceNOW”
workItem.summary = replica.summary
if (replica.ticket_type == “Incident”){
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Incident";
}else if(replica.ticket_type == “SCTASK”){
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "SCTASK";
}else if(replica.ticket_type == “ChangeRequest”){
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Change Request";
}else{
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Unknown";
}
store(workItem)
}
if(replica.ticket_type == “Incident”){
workItem.setStatus(replica.state)
workItem.summary = replica.summary
workItem.attachments = attachmentHelper.mergeAttachments(workItem, replica)
workItem.comments = commentHelper.mergeComments(workItem, replica)
store(workItem)
def ado_org_url = “Our URL Hardcoded“ //specially removed for sharing
def sysIdToFilename = replica.attachments.collectEntries { \[(it.remoteIdStr): it.filename\] }
def filenameToAdoId = workItem.attachments.collectEntries { \[(it.filename): it.idStr\] }
def pattern = /src="\\/sys_attachment.do\\?sys_id=(\[^"\]+)"/
def convertedHtml = replica.description.replaceAll(pattern) { fullMatch, sysId ->
def filename = sysIdToFilename\[sysId\]
if (filename) {
def adoId = filenameToAdoId\[filename\]
if (adoId) {
return "src=\\"${ado_org_url}/\_apis/wit/attachments/${adoId}?fileName=${filename}\\""
}
}
return fullMatch
}
workItem.description =convertedHtml
}
Hi @jvandeuren !
The script that you provided on the last comment is for incoming SNOW
Lets me explain again how the script should be paste
In Service now OUTGOING SCRIPT, PLEASE PASTE:
replica.u_html_1 = entity.u_html_1
You can then close SNOW as it’s not needed to change any script any more
Now on AZURE DEVOPS, PLEASE PASTE:
import java.util.regex.Matcher
import java.util.regex.Pattern
if(firstSync){
workItem.projectKey = "Demo_Agile"
workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Task";
}
workItem.summary = replica.summary
//workItem.description = replica.description
workItem.attachments = attachmentHelper.mergeAttachments(workItem, replica)
workItem.comments = commentHelper.mergeComments(workItem, replica)
workItem.labels = replica.labels
workItem.priority = replica.priority
store(issue)
def u_html_1 = replica.u_html_1
def replica_attachments = replica.attachments
def workitem_attachments = workItem.attachments
def await = { f -> scala.concurrent.Await$.MODULE$.result(f, scala.concurrent.duration.Duration$.MODULE$.Inf()) }
def orNull = { scala.Option<?> opt -> opt.isDefined() ? opt.get() : null }
def gsOptFuture = nodeHelper.azureClient.generalSettingsService.get()
def gs = orNull(await(gsOptFuture))
def trackerUrl = gs.issueTrackerUrl
def ado_org_url = trackerUrl+"/"+workItem.project.idStr
def sysIdToFilename = replica_attachments.collectEntries { [(it.remoteIdStr): it.filename] }
def filenameToAdoId = workitem_attachments.collectEntries { [(it.filename): it.idStr] }
def pattern = /src="\/sys_attachment.do\?sys_id=([^"]+)"/
def convertedHtml = u_html_1.replaceAll(pattern) { fullMatch, sysId ->
def filename = sysIdToFilename[sysId]
if (filename) {
def adoId = filenameToAdoId[filename]
if (adoId) {
return "src=\"${ado_org_url}/_apis/wit/attachments/${adoId}?fileName=${filename}\""
}
}
return fullMatch
}
workItem.description =convertedHtml
IF YOU COPIED THIS IN THE SERVICE NOW INCOMING SCRIPT PLEASE REMOVE IT, this should only be present in the ADO incoming script
Please try it again and comeback to us with feedback
BR
Tomas
Hello @Tomas_Lalanne,
In servicenow its send the html as entity.u_description_html U_html_1 does not exist and it send is as replica.description to devops.
We did exactly what the second script of @Sonal_Otwani did in incomming on devops side with the exception that we hardcode the ado_org_url as we will only use one project for this.
As far as i can see you are just a copy paste of your colleagues work, which does not help our case.
Please revert to us with actual questions or remarks.
Kind regards,
Jan-Baptist
Hi @jvandeuren
Thanks for the call on Friday. As per our discussion we created Jira ticket for you and we will continue there.
Thanks,
Sonal