レコードプロデューサーでSubmit時に添付ファイル数をチェックする方法

恵那白
Tera Contributor

こんにちは。

レコードプロデューサーのSubmit時に以下の標準の添付欄に添付されているファイル数を取得して、不足していれば警告を出すスクリプトを組みたいです。

_0-1770272791701.png

どうやっても添付ファイル数が取得できず…

皆様からアドバイスをいただきたいです。

 

2件の返信2

Nilesh Pol
Kilo Sage

Hi @恵那白 

You can use GlideAjax + Script include to retrieve the count of Attachments using GlideSysAttachment Class and block submit if file is missing.

try at your end and let us know when you stuck on code.

Ankur Bawiskar
Tera Patron

@恵那白 

if you are planning to run your code only in portal then this onSubmit catalog client script will give you the count of files

Note: This code will work only in portal and not native

function onSubmit() {

    var count = getRPAttachmentCount();
    if (count != 3) {
        g_form.addErrorMessage('You must add 3 attachments before submitting this request.');
        return false;
    }

}

function getRPAttachmentCount() {
    var length;
    try {
        length = angular.element("#sc_cat_item_producer").scope().attachments.length;
    } catch (e) {
        length = -1;
    }
    return length;
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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