We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Make Attachment mandatory in WS form

armanoj
Mega Sage

Hi ,

 

Make the attachment mandatory in the UI action button , when the button click , check attachment if there is no attachment then make attachment mandatory to submit that form.

8 REPLIES 8

@armanoj 

screenshot please of what you created

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

HI @armanoj ,

Do you want this validation to apply to all UI Actions that save or update the form,
or only for a specific UI Action?

Also, could you please share what you have implemented so far?

@Ankur Bawiskar  

specific UI Action
declarative action :

function onClick() {
    g_form.setMandatory('comments', true);

    if (!g_form.getValue('comments')) {
        g_form.addErrorMessage('Comments are mandatory');
        return;
    }
    var attachments = g_form.getAttachments();

    if (!attachments || attachments.length === 0) {
        g_form.addErrorMessage('Attachment is mandatory before approval.');
        return;
    }
    var status = g_form.getValue('u_sub_state');
    // g_form.setValue('state', '3');
    if (status == 'awaiting_yy_approval') {
        g_form.setValue('u_sub_state', 'awaiting_xx_approval');
    } else if (status == 'awaiting_zz_approval') {
        g_form.setValue('u_sub_state', 'approved');


    } else if (status == 'awaiting_mm_approval') {
        g_form.setValue('u_sub_state', 'awaiting_dd_approval');
    }

    // Save and refresh workspace
    g_form.save().then(function() {
        g_form.reload(); // Refresh workspace
    });
}

@armanoj 

so in workspace client script you want to check if attachment is added or not?

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