Creating comments on an Incident via Import Set

lucaburgazzoli
Mega Contributor

Hello,

I'm working on a ServiceNow connector that uses REST to interact with ServiceNow and as best practice recommends, I'm leveraging staging tables + transform map (Via Import Set REST API) to import data in a target table. Now I need to be able to add comments to an incident which is quite easy through a REST call targeting the incident table but that does not seems so simple if staging tables are used.

I've created:

  • a staging table named imp_incident_comments with the following fields:
    • element
    • element_id
    • name
    • value
  • a 1 to 1 transform map

It is not clear to me how such fields should be set. i.e. I've tried with a JSON like:

{

  "u_element": "external_id",

  "u_element_id": "my-external-id",

  "u_name": "incident",

  "u_value": "my comment"

}

The goals are:

  1. target an incident using an external id (but same issue happen when using sys_id as "link")
  2. avoid to add scripts in ServiceNow if possible as the integration should take place outside and transform map should be kept as simple as 1 to 1 map (if possible of course)

Any hint ?

2 REPLIES 2

lucaburgazzoli
Mega Contributor

I've been able to   insert a record in the table sys_journal_field with the following script:



requests.post(


      'https://my-instance.service-now.com/api/now/import/u_imp_incident_comments',


      auth       = (user, pwd),


      headers = { "Content-Type": "application/json", "Accept":"application/json" },


      data       = json.dumps({


              'u_element': 'comments',


              'u_element_id': 'ca6f88674f836600dabd4e318110c7a4',


              'u_name': 'task',


              'u_value': str(uuid.uuid1())


      })


)



Result:



{


  "import_set": "ISET0010015",


  "staging_table" :"u_imp_incident_comments",


  "result":[{


      "transform_map": "imp_incident_comments",


      "table": "sys_journal_field",


      "display_name": "name",


      "display_value": "comments",


      "record_link": "...",


      "status": "inserted",


      "sys_id": "560694a94f1fa600dabd4e318110c7c6" }]


}



And via REST I can see that my entry is in the sys_journal_field, but I do not see the comment on the incident:



{


  "result": {


      "parent": "",


      "made_sla": "true",


      "caused_by": "",


      "watch_list": "",


      "upon_reject": "cancel",


      "sys_updated_on": "2016-11-24 16:33:56",


      "child_incidents": "0",


      "approval_history": "",


      "number": "INC0010202",


      "resolved_by": "",


      "sys_updated_by": "admin",


      "opened_by": {


          "link": "...",


          "value": "d2f33d344f78a600dabd4e318110c7ef"


      },


      "user_input": "",


      "sys_created_on": "2016-11-18 11:05:57",


      "sys_domain": {


          "link": "...",


          "value": "global"


      },


      "state": "1",


      "sys_created_by": "xyz",


      "knowledge": "false",


      "order": "",


      "calendar_stc": "",


      "closed_at": "",


      "cmdb_ci": "",


      "delivery_plan": "",


      "impact": "2",


      "active": "true",


      "work_notes_list": "",


      "business_service": "",


      "priority": "4",


      "sys_domain_path": "/",


      "rfc": "",


      "time_worked": "",


      "expected_start": "",


      "opened_at": "2016-11-18 10:14:13",


      "business_duration": "",


      "group_list": "",


      "work_end": "",


      "caller_id": {


          "link": "...",


          "value": "d2f33d344f78a600dabd4e318110c7ef"


      },


      "resolved_at": "",


      "approval_set": "",


      "subcategory": "",


      "work_notes": "",


      "short_description": "sadfasdfasdfasdf",


      "close_code": "",


      "correlation_display": "",


      "delivery_task": "",


      "work_start": "",


      "assignment_group": "",


      "additional_assignee_list": "",


      "business_stc": "",


      "description": "",


      "calendar_duration": "",


      "close_notes": "",


      "notify": "1",


      "sys_class_name": "incident",


      "closed_by": "",


      "follow_up": "",


      "parent_incident": "",


      "sys_id": "ca6f88674f836600dabd4e318110c7a4",


      "contact_type": "email",


      "incident_state": "1",


      "urgency": "3",


      "problem_id": "",


      "u_external_id": "SF-5000Y000001Haa0QAC-00001110",


      "company": "",


      "reassignment_count": "0",


      "activity_due": "",


      "assigned_to": "",


      "severity": "3",


      "comments": "",


      "approval": "not requested",


      "sla_due": "",


      "comments_and_work_notes": "",


      "due_date": "",


      "sys_mod_count": "1",


      "u_reporter": "",


      "reopen_count": "0",


      "sys_tags": "",


      "escalation": "",


      "upon_approval": "proceed",


      "correlation_id": "",


      "location": "",


      "category": "software"


  }


}



Anything I missed ?


Hi All,



I have a similar type of REST setup in Eureka version and its working except for additional comments & work Notes. And I am trying to convert these Journal Inputs entries to String and placed it in String field in import set staging table. Below is line of code:-



var comm= inc.comments.getJournalEntry(-1).toString();  


comm=comm.replace(/["']/g, "");  


comm=comm.replace(/[\n*]/g, "");      


comm=   String(comm);



r.setStringParameter('u_additional_comments',comm);


gs.log('Comments :' + comm);



But its appearing as blank. However, on log its prints properly.I also tried by passing the hardcoded value through content type and that was working.


Any idea where its getting wrong and what?