I'm trying to set a Servicenow Duration field with an String Jira field

Have anyone done this? I’m trying to Sync a jira filed that contains a duration like this: “1 Day 2 hours 30 minutes” to a ServiceNow field that when I look at the local replica it sends the values like this, not sure what I’m mising, I’ve tried to send the value, thevalue.toString() formated the string but nothing seems to be working

image

Hi @Juan_Manuel_Alarcon ,

The formats on both sides are radically different indeed, so some manipulation would be required. If you check the remote replica from SNOW, and give us the exact thing being received for the field, it would help. It would also help to understand the exact type of field in SNOW where you are trying to write this.

Here is an example that works for me in my system:

Send due date from Jira:

replica.due = issue.due

Process it on SNOW Incoming to populate the work_start field:

if(replica.due) {
    Calendar calendar = Calendar.getInstance()
    calendar.timeInMillis = replica.due.time
    
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    entity.work_start = dateFormat.format(calendar.time)
}

Hopefully, it gives you some ideas around the subject.

Thanks
Majid

Hi @Majid thanks for sharing that part of the code.

I’m trying to set the Duration and the field type on servicenow is glide_duration, and it looks like it sends an string to Exalate (see the first screenshot on the ticket), it sends somthing like: 1 Day 1 Hour 30 minutes, I’ve tried to send it like and string but nothing seems to be working

image

Hi Juan,

What if you try:

def durationStr = replica.customFields."duration"?.value
if (durationStr) {
    incident.u_duration_of_downtime = new GlideDuration(durationStr).getValue()
}

Kind regards,

Ariel

HI Ariel,

Thanks for the tip, but what library do I have to import for this to work, as it doesn’t alllow me to save the code and the error is the following:

Error: 'Script cannot be saved. Details: startup failed:
Script4.groovy: 659: unable to resolve class GlideDuration
@ line 659, column 49.
tity.u_duration_of_downtime = new GlideD
^

1 error

Hi Juan,

I was getting slightly confused as to what we eventually want to do with this field value.
Here is a couple of attempts to process it on Jira side:

The script I used on Jira side to process this into due date is:

// Parse the duration string from replica
def durationText = replica.u_dd
if (durationText) {
    // Initialize total milliseconds
    long totalMs = 0
    
    // Extract days, hours, minutes using regex
    def daysMatch = (durationText =~ /(\d+)\s*Day/)
    def hoursMatch = (durationText =~ /(\d+)\s*Hour/)
    def minutesMatch = (durationText =~ /(\d+)\s*Minute/)
    
    if (daysMatch.find()) {
        totalMs += Long.parseLong(daysMatch.group(1)) * 24 * 60 * 60 * 1000
    }
    if (hoursMatch.find()) {
        totalMs += Long.parseLong(hoursMatch.group(1)) * 60 * 60 * 1000
    }
    if (minutesMatch.find()) {
        totalMs += Long.parseLong(minutesMatch.group(1)) * 60 * 1000
    }
    
    // Calculate due date = now + duration
    def dueDate = new Date(System.currentTimeMillis() + totalMs)
    
    // Set the due_date field
    issue.due = dueDate
}

Hope it helps!

Thanks
Majid