As of the Berlin release, there is an issue with the way Import Sets handle JSON Web Service posts that is inconsistent with how Import Sets respond to SOAP web service calls.

As you know, an Import Set will accept data from a third party. When the data is written to the import set table, it then is processed by a transform map and a resulting record is created on a target table.

If you post to the Import Set through a SOAP web service, you are given the resulting target record with the synchronous SOAP Response.

With JSON, however, the import set table doesn’t wait for the transformation. It just responds with the record in the import set table before the transformation. This makes it a bit troublesome if you need to get the ID or Display Value of the resulting record.

In order to get around this issue with the least amount of work and still be able to post directly to the import set table, you can use the following workaround.

Sample Scenario

We want to post a new message to the imp_notification import set on our instance via a REST call using the JSON Web Service.

We submit the following with our REST-based client:

REST URL:

http://now.ht4.org:8080/imp_notification.do?JSON&sysparm_action=insert

POST CONTENT:

{"message":"this is a test","severity":"1", "uuid":"1289351"}

With that call, we get the following response:
RESPONSE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
   "records":[
      {
         "assignment_group":"",
         "category":"",
         "comments":"",
         "corrective_message":"",
         "duration":"",
         "expires_on":"",
         "message":"this is a test",
         "severity":"1",
         "source":"",
         "state":"",
         "sys_class_name":"imp_notification",
         "sys_created_by":"admin",
         "sys_created_on":"2013-03-13 20:22:15",
         "sys_id":"6fc2a6de3d8c8100da96ed03316ef125",
         "sys_import_row":"1",
         "sys_import_set":"b682ea123dcc8100da96ed03316ef17d",
         "sys_import_state":"pending",
         "sys_import_state_comment":"",
         "sys_mod_count":"0",
         "sys_row_error":"",
         "sys_target_sys_id":"",
         "sys_target_table":"",
         "sys_transform_map":"",
         "sys_updated_by":"admin",
         "sys_updated_on":"2013-03-13 20:22:15",
         "timestamp":"",
         "type":"",
         "uuid":"1289351"
      }
   ]
}

This response comes to you immediately before the transform takes place. Notice the following key fields and their values:

sys_id:“6fc2a6de3d8c8100da96ed03316ef125”
sys_import_state:“pending”

The sys_id field in the response is the sys_id of the record created as a row on the import set table.

The sys_import_state field tells you what state that row is currently in. “pending” means that it was created in the table, but it has not been processed by the transform map yet.

In order to get the resulting record information for post-transform, you need to make a second REST call to query that very import set record you created to see what happened to it.

POST URL:

http://now.ht4.org:8080/imp_notification.do?JSON&sysparm_action=get&sysparm_sys_id=6fc2a6de3d8c8100da96ed03316ef125&displayvalue=all

Please notice on the URL, I have a query parameter: displayvalue=all. This tells the web service to respond with display values as well as sys_id’s for all reference fields on the table.

In this case, we get the following response
RESPONSE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
   "records":[
      {
         "assignment_group":"",
         "category":"",
         "comments":"",
         "corrective_message":"",
         "duration":"",
         "dv_assignment_group":"",
         "dv_category":"",
         "dv_comments":"",
         "dv_corrective_message":"",
         "dv_duration":"",
         "dv_expires_on":"",
         "dv_message":"this is a test",
         "dv_severity":"1",
         "dv_source":"",
         "dv_state":"",
         "dv_sys_class_name":"Notification",
         "dv_sys_created_by":"admin",
         "dv_sys_created_on":"2013-03-13 20:22:15",
         "dv_sys_id":"6fc2a6de3d8c8100da96ed03316ef125",
         "dv_sys_import_row":"1",
         "dv_sys_import_set":"ISET0010034",
         "dv_sys_import_state":"Inserted",
         "dv_sys_import_state_comment":"",
         "dv_sys_mod_count":"1",
         "dv_sys_row_error":"",
         "dv_sys_target_sys_id":"INC0010032",
         "dv_sys_target_table":"incident",
         "dv_sys_transform_map":"Notification",
         "dv_sys_updated_by":"admin",
         "dv_sys_updated_on":"2013-03-13 20:22:16",
         "dv_timestamp":"",
         "dv_type":"",
         "dv_uuid":"1289351",
         "expires_on":"",
         "message":"this is a test",
         "severity":"1",
         "source":"",
         "state":"",
         "sys_class_name":"imp_notification",
         "sys_created_by":"admin",
         "sys_created_on":"2013-03-13 20:22:15",
         "sys_id":"6fc2a6de3d8c8100da96ed03316ef125",
         "sys_import_row":"1",
         "sys_import_set":"b682ea123dcc8100da96ed03316ef17d",
         "sys_import_state":"inserted",
         "sys_import_state_comment":"",
         "sys_mod_count":"1",
         "sys_row_error":"",
         "sys_target_sys_id":"2fc22e123dcc8100da96ed03316ef14f",
         "sys_target_table":"incident",
         "sys_transform_map":"471a69c30a0a0b2400a26dda9456fac2",
         "sys_updated_by":"admin",
         "sys_updated_on":"2013-03-13 20:22:16",
         "timestamp":"",
         "type":"",
         "uuid":"1289351"
      }
   ]
}

The fields of most interest in this response are the following:
sys_import_state:“inserted”
sys_target_sys_id:“2fc22e123dcc8100da96ed03316ef14f”
sys_target_table:“incident”
dv_sys_target_sys_id:“INC0010032”

The sys_import_state tells us in this case whether the record was inserted, updated, or still in pending state. There are other possible values as well.

The sys_target_sys_id field gives us the sys_id of the record that was created/updated in the target table

The sys_target_table tells us which table the record was created/updated in. (eg. incident)

The dv_sys_target_sys_id field tells us the Display Value of that record (eg. INC0010032)