Reputation: 3472
We try to synchronize a Jira timestamp field to servicenow.
Several time ago we did the same for the problem module with success.
Now we try to do the same for Request Items in servicenow
The Jira field is event timestamp custom field and we use the following code :
if(replica.customFields.eventTimestamp && replica.customFields.eventTimestamp.value){
// Define timestamps
def timestamps = replica.customFields.'eventTimestamp'.value
// Set a date using the timestamp
def date = new Date(timestamps.time)
// Create a date format as desired
SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-mm-dd hh:mm:ss")
requestItem.u_event_timestamp = dateFormat.format(date)
}
When we do a sync we didn’t get an error but the field is not updated.
Upvotes: 0
Views: 49
Reputation: 59
please try to use the Jira Spoke and webhook and existing OOTB sub-flow.
Upvotes: 0
Reputation: 3472
The script that you are using seems to properly retrieve and transform the timestamp from the replica. However, one thing to take note of is that when setting the received value in ServiceNow, you need to use the column name of ServiceNow field, not the display name.
If 'u_event_timestamp' is the display name, you need to identify the correct column name and use it in your script.
Also, please ensure that the field 'u_event_timestamp' in ServiceNow is the appropriate type to hold the date timestamp value.
Furthermore, the pattern you use for SimpleDateFormat should be "yyyy-MM-dd HH:mm:ss" (note that MM should be uppercase for month and HH for 24-hour format).
Here is the corrected script:
if(replica.customFields.eventTimestamp && replica.customFields.eventTimestamp.value){
// Define timestamps
def timestamps = replica.customFields.'eventTimestamp'.value
// Set a date using the timestamp
def date = new Date(timestamps.time)
// Create a date format as desired
SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
requestItem.u_event_timestamp = dateFormat.format(date)
}
Please refer to this documentation for more details: How to synchronize different field types on ServiceNow
If you are still experiencing errors, it's best to recheck the field mapping and the sync rules.
Upvotes: 0