Service Catalog Attachment

AnilJ
Tera Contributor

I have a requirement where there is an attachment type field(e.g.,  diso_approval) if it contains only .msg file then submit the request; otherwise unable to submit form.

Note: Variable Atrribute not working( Need a script). 

1 ACCEPTED SOLUTION

@AnilJ 

seems your form doesn't have that field

add this from list in the variable attributes for that variable allowed_extensions=msg

AnkurBawiskar_0-1740049639227.png

From list you can add if you don't want to make any form layout

AnkurBawiskar_1-1740049680965.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

9 REPLIES 9

@AnilJ 

seems your form doesn't have that field

add this from list in the variable attributes for that variable allowed_extensions=msg

AnkurBawiskar_0-1740049639227.png

From list you can add if you don't want to make any form layout

AnkurBawiskar_1-1740049680965.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

Yes.. it's working now.

Thanks for your Support!!

Sourabh Tarlekr
Kilo Sage

Hi 

You can use Glide Ajax in Client Script and Script Include to get the attachment content type from sys_attachment form and compare the response. For .msg file the content type is application/vnd.ms-outlook

 

Please use below code and let me know if this works for you.

 

Create On Change Client Script for Attachment field.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var cartId = g_form.getParameter('sysparm_item_guid'); // finds the card id
    var ga = new GlideAjax('AZFCMassHelper');
    ga.addParam('sysparm_name', 'getAttachmentType');
    ga.addParam('sysparm_cartID', cartId);
    ga.getXMLWait();

    var answer = ga.getAnswer()
    if (answer != "application/vnd.ms-outlook") {
        g_form.addErrorMessage('Only .msg file allowed. Attached file is: ' + answer);
        return false;
    } else return true;
}

 

Script Include

 getAttachmentType: function() {
        var cartid = this.getParameter('sysparm_cartID');
        var gr = new GlideRecord('sys_attachment');
        gr.addQuery('table_sys_id', cartid);
        gr.query();
        
		if(gr.next())
		{
			return gr.content_type;
		}
    },

 

Please find below screenshot for reference:

Getting error file other file types

SourabhTarleka_0-1740047637757.png

 

 

For .msg file attachment is allowed and no error is getting

SourabhTarleka_1-1740047696743.png

 

 

Please let me know i this solution works for you and mark as "Accept/Helpful".

 

Regards,

Sourabh

Renat Akhmedov
Tera Contributor

Hi, please try this solution, it should work for you, 

 

function onSubmit() {
    var fieldName = 'diso_approval';
    var attachments = g_form.getValue(fieldName);
    
    if (!attachments) {
        return true;
    }

    var validFilePattern = /\.msg$/i; // Regular expression to validate .msg file

    var attachmentList = attachments.split(',');

    for (var i = 0; i < attachmentList.length; i++) {
        var fileName = attachmentList[i].trim();
        if (!validFilePattern.test(fileName)) {
            return false;
        }
    }

    return true;
}

 

 

If it helped you - please mark it as helpful answer,

Best regards,
Renat Akhmedov

@Renat Akhmedov ,

I used the above script and now I am getting the following error while uploading the .msg file.

AnilJ_0-1740051257516.png