sys_attachment without the right content_type info

Yonix
Tera Contributor

Fotos not displayed in the WEB application in the Workspace after being uploaded with an Android device.


When the user submits a form in the now agent app with some attachments, the records created in the table sys_attachment do not contain the right info in the field content_type. It is image/* instead of image/jpeg or image/png.

In the now agent app, the user can see the image but in the WEB the user receives an error "The datafile is not supported".

Here is the process.
1) In the Mobile App Builder we have a Mobile function[sys_sg_button] which has an action item[sys_sg_write_back_action_item]. See attachment "001_Mobile_function.png"

2) This action item is a script that calls a function "proccedModule" on a Script Include "mobileMain". See attachment "002_Action_item.png"

3) Here is the code:

proccedModule: function(parm_input, parm_variable, actionResult, module_num) { 
    //prepare update set
    var filteredInputs = {
            "fields": [],
            "attachments": []
        },
        module = module_num;

    //is first update
    if (parm_variable.status_module == "false")
        filteredInputs.fields.push({
            "key": "status_module_" + module,
            "value": true
        });
    
    //if in module 7 "extension not needed", set module 8 to completed
    if (parm_input.bep_extension == "extension_not_needed")
        filteredInputs.fields.push({
            "key": "status_module_8",
            "value": true
        });		

    for (var input in parm_input) {
        if (parm_input[input] != "undefined") {
            if (input.indexOf("picture") == -1) {
                filteredInputs.fields.push({
                    "key": input,
                    "value": parm_input[input]
                });
            } else {
                filteredInputs.attachments.push(input);
            }
        }
    }
    
    //gs.info("DRA: " + parm_input.bep_extension);
    //gs.info("DRA: " + global.JSON.stringify(filteredInputs));

    //proceed update set
    var now_GR = new GlideRecord('x_cx1_sar_location');
    if (now_GR.get(parm_variable.cp_id)) {
        filteredInputs.fields.forEach(function(el) {
            now_GR.setValue(el.key, el.value);
        });
        now_GR.update();

        //proceed attachments
        filteredInputs.attachments.forEach(function(el) {

            //check for existing record
            var sysId,
                name = "md_" + module + "_" + el,
                existingAttachment = new GlideRecord("x_cx1_sar_mobile_attachments");
            existingAttachment.addQuery("order", parm_variable.sys_id);
            existingAttachment.addQuery("name", name);
            existingAttachment.setLimit(1);
            existingAttachment.query();
            if (existingAttachment.next()) {
                sysId = existingAttachment.getValue("sys_id");
            } else {

                //else create new
                var newAttachment = new GlideRecord("x_cx1_sar_mobile_attachments");
                newAttachment.initialize();
                newAttachment.name = name;
                newAttachment.order = parm_variable.sys_id;
                sysId = newAttachment.insert();
            }

            actionResult.addAttachment(el, "x_cx1_sar_mobile_attachments", sysId);
        });

    }
},

The attachments are added to both tables. But in the sys_attachment the value of the field Content type is "image/*" and that why we are getting the error "The datafile is not supported". See the attachment "003_sys_attachment.png".

In the attachment "004_x_cx1_sar_mobile_attachments.png" you can see the fields from this custom table that we use to know the version of the attached image.

From the process that I have described here does anyone know how can we get the right value under the field content_type in sys_attachment table?

Thanks


 

2 REPLIES 2

EbrahimAli
ServiceNow Employee
ServiceNow Employee

Hi @Yonix 
Did you able to solve this ?

another question can we prevent the file uploading  from attachment input?

Yonix
Tera Contributor

Hi @EbrahimAli,

no, I'm still looking if someone can help me. 😉