Pradyumna Das
Tera Expert

Servicenow has restricted a few data types like Attachment, Container start, etc in the multi-row variable set. If you really want to use those data types in your multi-row variable set please modify the below business rule based on your condition and then change the data type of the variable.

OOB Business rule Name: Restrict types for table variable set

BR Written on Table: Variable[item_option_new]

BR Scope: Global

The exceptional script is needed if you want the Attachment type variable should work properly.

Reason: If the user will add multiple rows with attachments and submit the form the attachments will not reflect in the new reocrd. As this will store in the attached table with different table names and also stores the table_sys_id field value as the MRVS sys_id.

Solution:  Create a script include(New Class) in the global scope and create the below function inside the script include.

updateAttachmentData: function(recordID) {
        /*Update the table name and table sys_id for the attachment MRVS*/
        var attachment = new GlideRecord('sys_attachment');
        attachment.addQuery('table_sys_id', '<MRVS Sys_id>'); //  MRVS Sys ID
        attachment.query();
        while (attachment.next()) {
            attachment.table_sys_id = recordID.toString();// Newly created record sys_id
            attachment.table_name = '<Type your table name>';
            attachment.update();
        }
    }

Then call this function inside the record producer script or call this function inside an insert BR on your table.

Please mark it helpful if somehow it helps you to achieve your goal.

 

Output:

Please find the blow attachments for the result.

 

 

 

 

Comments
Fernando36
Tera Explorer

Hello Pradyumna,

 

Thanks for share your solution, I'd like know If can you help, can you share the screen of your Script Include and your BR?

 

On your BR I'd like know, whats the action type and see the script that you writed to call the script include.

 

Thanks.

priti4
Tera Contributor

Hello @Fernando36 

 

you can follow the above steps to add the "Attachment" variable in the MRVS.
and after that you can use the below code with Business Rule instead of Script Include.
 
Please refer to the below details for your reference:
 
Table: Request [sc_request]
When to Run: After Insert
Script:
 

var grRitm = new GlideRecord('sc_req_item');
grRitm.addQuery('request', current.sys_id);
grRitm.query();
while (grRitm.next()) {
var gr1 = new GlideRecord('sc_multi_row_question_answer');
gr1.addQuery('parent_id', grRitm.sys_id);
gr1.addQuery('item_option_new', 'MRVs variable sys_id');
gr1.query();
while (gr1.next()) {
var attchment = new GlideRecord('sys_attachment');
attchment.addQuery('sys_id', gr1.value);
attchment.query();
while (attchment.next()) {
attchment.table_sys_id = grRitm.sys_id;
attchment.table_name = 'sc_req_item';
attchment.update();
}
}

}

 

 

image (12).png

raj71
Tera Explorer

Thanks. This seems to be very helpful for my project

monika94
Kilo Guru

Hi @Pradyumna Das,

 

This solution allows only one attachment to be attached to the row. Unless we add multiple attachment type variables. Other than that, is there any way, we can allow multiple attachments?

 

Regards,

Monika 

 

Pradyumna Das
Tera Expert

@monika94 

It will work for multiple attachments. If you are using MRVS as well it will work. 

mipalm
Tera Guru

Hi,

I've trie this approach but its only displaying the string with the file name instead of the actual string, any idea why?

ZiadZ
Tera Contributor

Thanks for the write up, can anyone explain why this business rule exist in the first place? Is this preventing any issues related to performance or security if we do attachments as part of a MVRS?

Praveen Mariapp
Tera Contributor

I have the same question as @ZiadZ mentioned. Is there any specific reason the attachment is not supported within MRVS by default?

 

Regards,

Praveen

SwarnadeepNandy
Mega Sage

Hello All,


This solution looks too good to be true, but it has huge consequence.


As Multi Row Variable Set sys_id is fixed all attachments are getting attached with

table_name = "ZZ_YYsc_cart_item"

table_sys_id = <multi row variable set sys_id>.

 

Meaning everyone requesting this catalog item will have all the attachments stored under that single record.

So, imagine if multiple people requesting the Catalog item at the same time, due to the Business Rule, whoever clicks submit first all the attachment from the fixed MultiRow Variable Set will get attached into the RITM of that particular requestor.
Which essentially means attachment from one RITM MutiRow Varibale set will go to another RITM(unintended one).

Kind Regards,
Swarnadeep Nandy

Version history
Last update:
‎07-20-2022 09:51 AM
Updated by: