Add Attachment Category for an Attachment record in Incident Table

Chandrima Mukh2
Tera Contributor

Hello Everyone,

 

In Service Operations Workspace, I am looking for a way to add an attachment category for an attachment.

I have tried

  • Adding a custom field in the Attachment pane of Service Operations Workspace. Couldn't find any solution
  • I have tried an UI action which I am unable to complete. GlideModal is not working in Workspace. I am unable to script g_modal for attachment field type.
  • I have created a client-type Action Assignment for attachements. However I am not able to get the sys_id of the attachment using Action Assignment client script. Below is my script for Action Assignment.

 

 

 

 

function onClick() {

    var ga = new GlideAjax('GetMyChoices');
    ga.addParam('sysparm_name', 'getFieldChoices');
    ga.getXMLAnswer(function(answer1) {
        var answer = JSON.parse(answer1);
        fields.push({
            type: 'choice',
            name: 'u_category',
            label: getMessage('Document Category'),
            choices: answer.choices,
            mandatory: true
        });
        g_modal.showFields({
            title: "Upload Document Category",
            fields: fields,
            size: 'lg'
        }).then(function(fieldValues) {
            alert("Hiiii inside Modal = " + fieldValues.updatedFields[0].value);
        });
    });
}

 

 

 

Can anyone please help me how do I get SysId of an attachment or attachmentName to achieve a solution for this.

 

note: I have created a custom field "Category" in sys_attachment table which will hold the value for the attachment category.

1 REPLY 1

Rajdeep Ganguly
Mega Guru


Unfortunately, as of now, ServiceNow does not support the customization of the attachment category in the Service Operations Workspace. The Workspace UI is not as flexible as the platform UI and does not support GlideModal or g_form in the same way.

However, you can try the following workaround:

1. Create a separate table to hold the attachment and its category.
2. Create a record producer or a custom UI page to upload the attachment and select the category.
3. Use a business rule or a script include to move the attachment from the custom table to the sys_attachment table and delete the record from the custom table.

Here is a sample script for the business rule:

javascript
(function executeRule(current, previous /*null when async*/) {
var sa = new GlideRecord('sys_attachment');
sa.addQuery('table_name', 'your_custom_table');
sa.addQuery('table_sys_id', current.sys_id);
sa.query();
while (sa.next()) {
sa.table_name = 'incident'; // or any other table you want to move the attachment to
sa.table_sys_id = current.incident; // the sys_id of the record you want to attach the file to
sa.u_category = current.u_category; // your custom category field
sa.update();
}
current.deleteRecord();
})(current, previous);


Please note that this is a workaround and might not be the best solution for your use case. It's always recommended to check with ServiceNow support or community for the best practices and solutions.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER