Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

attachments mandatory based on the Short Description of a Task

Dileep Raju
Giga Guru

attachments mandatory based on the Short Description of a Task and only for one task

6 REPLIES 6

folusho
Tera Guru

@Dileep Raju 

 

You can use either onSubmit Client script or BR>

 

function onSubmit() {
    // Only apply to specific short description
    if (g_form.getValue('short_description') !== 'Submit Design Document') {
        return true;
    }

    // Check for attachments
    var attachments = g_form.getAttachments();
    if (!attachments || attachments.length === 0) {
        g_form.showFieldMsg('short_description', 'Attachment is required for this task.', 'error');
        return false;
    }

    return true;
}

 

 

create a Business Rule on the task table (or your specific task type like sc_task or pm_task)

....When: before

....Insert & Update: 

....Condition: current.short_description == 'Submit Design Document'

(function executeRule(current, gS, gE, gR) {
    var att = new GlideRecord('sys_attachment');
    att.addQuery('table_sys_id', current.sys_id);
    att.addQuery('table_name', current.getTableName());
    att.query();

    if (!att.hasNext()) {
        gs.addErrorMessage('Attachment is required for this task.');
        current.setAbortAction(true);
    }
})(current, gs, g_event, g_request);

 

Hi @Gaurav Rathaur 
Still not working
and I need one more condition based on yes or no varibale