Created attachment is not getting saved to sys_attachement table .(Issue with create & Retrive attachment)

p_27
Kilo Contributor

HI ,

I have created a attachment & tried to retrieve it by passing id it returns 404 .Adding details below

CASE I

Create Attachment 

POST : https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true

Request Body : { source: 'alm_asset:1cab288d3790200044e0bfc8bcbe5d43',
name: 'dev87746.txt',
agent: 'AttachmentCreator',
topic: 'AttachmentCreator',
payload: 'dev87746 service instnace in use' }

Response : Received response 401 from POST call to https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true 

It says 401 & still returns response  : {"file_name":"dev87746.txt","sys_id":"74c34891db51101065a42946489619a8","FileContent":"dev87746 service instnace in use","AttachmentOwnerType":"alm_asset","AttachmentOwnerId":"00aa7c9edb401010aad88809489619aa"}

Retrive :

Now when i tried to get the attachement by :https://dev87746.service-now.com/api/now/table/sys_attachment/74c34891db51101065a42946489619a8?sysparm_exclude_reference_link=true

it returns 404 .

Retrive Response : {
"error": {
"detail": "Record doesn't exist or ACL restricts the record retrieval",
"message": "No Record found"
},
"status": "failure"
}

CASE II

POST : https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true

This Api returns 201 me sometimes . 

RequestBody :  { source: 'alm_asset:1cab288d3790200044e0bfc8bcbe5d43',
name: 'dev87746.txt',
agent: 'AttachmentCreator',
topic: 'AttachmentCreator',
payload: 'dev87746 service instnace in use' }

Response: Successful response 201 from POST call to https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true

Response received:  {"file_name":"dev87746.txt","sys_id":"6a0a88d9db51101065a42946489619fc","FileContent":"dev87746 service instnace in use","AttachmentOwnerType":"alm_asset","AttachmentOwnerId":"00aa7c9edb401010aad88809489619aa"}

Retrive : https://dev87746.service-now.com/api/now/table/sys_attachment/6a0a88d9db51101065a42946489619fc?sysparm_exclude_reference_link=true 

Retrive response : 404 

{
"error": {
"detail": "Record doesn't exist or ACL restricts the record retrieval",
"message": "No Record found"
},
"status": "failure"
}

Note : The user role is set to Admin .

10 REPLIES 10

Hi,

In the response you receive from this API Call; there isn't any sys_id of sys_attachment table

So that's correct the bold part is not sys_id of sys_attachment

please confirm by visiting the sys_attachment table and try to search with this sys_id

When I tried it gave me http 201 correct status

Are you still facing issue in posting an attachment to table record?

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Is this answered?

if my answer helped you, kindly mark it as Correct & 👍Helpful so that it does not appear in unanswered list & close the thread.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Is this answered?

if my answer helped you, kindly mark it as Correct & 👍Helpful so that others can benefit from similar question in future.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

ashvini
Kilo Contributor

thanks Ankur for the reply. This was very useful.

Actually the scenario goes like this.

step 1: Post call to create the attachment

https://dev74201.service-now.com//api/now/table/ecc_queue?&sysparm_exclude_reference_link=true

{
   "source":"incident:1c741bd70b2322007518478d83673af3",
   "name":"brajmohan.txt:text/plain",
   "agent":"AttachmentCreator",
   "topic":"AttachmentCreator",
   "payload":"b2theSBzZXJ2aWNlbm93"
}

Got response from ServiceNow:

{
    "result": {
        "agent": "AttachmentCreator",
        "response_to": "",
        "sys_mod_count": "0",
        "from_sys_id": "",
        "source": "incident:1c741bd70b2322007518478d83673af3",
        "sys_updated_on": "2020-06-09 17:28:31",
        "agent_correlator": "",
        "priority": "2",
        "sys_domain_path": "/",
        "error_string": "",
        "processed": "",
        "sequence": "1729a205a860000001",
        "sys_id": "0f205f692f111010424859a72799b64f",
        "sys_updated_by": "admin",
        "from_host": "",
        "payload": "Attachment created and attached to 'incident' record with sys_id: '1c741bd70b2322007518478d83673af3'",
        "sys_created_on": "2020-06-09 17:28:31",
        "sys_domain": "global",
        "name": "brajmohan.txt:text/plain",
        "topic": "AttachmentCreator",
        "state": "processed",
        "queue": "input",
        "sys_created_by": "admin"
    }
}

 

Step 2: do a get by ID call on sys_attachment

 

https://dev74201.service-now.com//api/now/table/sys_attachment/0f205f692f111010424859a72799b64f

{
    "error": {
        "message": "No Record found",
        "detail": "Record doesn't exist or ACL restricts the record retrieval"
    },
    "status": "failure"
}

 

This fails but if I do get all attachments on the above incident and pick sys_id from there, I notice its a different sys_id all together and the get by ID + getting content both works on that sys_id.

 

https://dev74201.service-now.com//api/now/table/sys_attachment?sysparm_query=table_sys_id=1c741bd70b2322007518478d83673af3^AttachmentOwnerType=incident&sysparm_exclude_reference_link=true&sysparm_view=false&sysparm_display_value=false&sysparm_suppress_pagination=false&sysparm_limit=100

 

{
            "size_bytes": "15",
            "file_name": "brajmohan.txt",
            "sys_mod_count": "1",
            "average_image_color": "",
            "image_width": "",
            "sys_updated_on": "2020-06-09 17:28:40",
            "sys_tags": "",
            "table_name": "incident",
            "sys_id": "8f205f692f111010424859a72799b64f",
            "image_height": "",
            "sys_updated_by": "system",
            "content_type": "text/plain",
            "sys_created_on": "2020-06-09 17:28:31",
            "size_compressed": "35",
            "compressed": "true",
            "state": "available",
            "table_sys_id": "1c741bd70b2322007518478d83673af3",
            "chunk_size_bytes": "734003",
            "sys_created_by": "admin"
        },

 

In summary, the sys_id that we got in POST call response is not working. To get the attachment created by POST call, we have to first get all attachments, select sys_id from response and then do /file call to get content.

 

Let us know with your thoughts.

 

 

thanks,

 

Hi,

So are you saying once you POST the attachment you need to get content of same attachment in immediate call?

If yes then you should have the sys_attachment record sys_id; without that I don't think you can get the content

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader