The import comments and work notes to ServiceNow.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2023 10:39 PM
We try to import comments and work notes to ServiceNow.
We did the transform map to load the data to Journal Entry [sys_journal_field] table.
one after script, we did insert the sys_audit and update the ticket record.
But it was not working until we save the ticket again after import, the activity will be shown.
insertAudit: function(target_sys_id, target_value,target_table_name,target_created_on)
{
var sAudit = new GlideRecord("sys_audit");
sAudit.addQuery("documentkey", target_sys_id);
sAudit.query();
var count = parseInt(sAudit.getRowCount());
var nAudit = new GlideRecord("sys_audit");
nAudit.documentkey = target_sys_id;
nAudit.fieldname = "comments";
nAudit.oldvalue ="JOURNAL FIELD ADDITION";
nAudit.newvalue = target_value;
nAudit.reason = "Migrated from Remedy";
nAudit.record_checkpoint = count + 1;
nAudit.internal_checkpoint = gdtToCheckpoint(new GlideDateTime(target_created_on));
nAudit.tablename = target_table_name;
// Set the audit user information information
nAudit.sys_created_by = gs.getUserName();
nAudit.sys_created_on = target_created_on;
nAudit.user = gs.getUserName();
nAudit.autoSysFields(false);
nAudit.insert();
var gr = new GlideRecord(target_table_name);
if (gr.get(target_sys_id)) {
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.setValue("sys_mod_count", count + 1);
gr.update();
}
function gdtToCheckpoint(gdt)
{
var n = gdt.getNumericValue();
return n.toString(16) + "0000001";
}
},
I suspect the code has issue,
var gr = new GlideRecord(target_table_name);
if (gr.get(target_sys_id)) {
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.setValue("sys_mod_count", count + 1);
gr.update();
}
the sys_mod_count was not be updated. Please help to correct this
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 04:44 AM
sorry, it has been included in my code.
gr.setWorkflow(false);
the issue is after the audit inserted, the history table not been generated automatically. I am still looking for the root cause.