How to make Attachment Mandatory for Record Prouder request created in a Scoped Application?

Salah2
Tera Contributor

Hi all, 

Created a Record Producer within an Application Scope from App Engine Studio.  We are struggling to make attachment mandatory.  

Requirement: If "id_required_for_every_employer" is "Yes", then set Attachment Mandatory/prevent request submission | Field type:  Option - Yes/No

Release version: Utah 

Script Include: 

Name:CheckAttachPRecodProducer | Client callable: true | Application: Fow Application | Accessible: This App scrope

 

var CheckAttachPRecodProducer = Class.create();
CheckAttachPRecodProducer.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
CheckAttachments: function() {
        var pForm = this.getParameter('sysparm_p_form');
        var pForm = new GlideRecord("sys_attachment");
        pForm.addQuery('table_name', "x_appl_di_tile_form");
        pForm.addQuery('table_sys_id', dataCheck);
        pForm.query();

        if (gr.next()) {
            return 'yes';
        } else {
            return 'no';
        }
    },
    type: 'CheckAttachPRecodProducer'
});

 

Catalog Client Scripts: 

Applies: Catalog Item | UI Type: All | Type: onChanage | CatalogItem: Fow Request | VariableName: id_required_for_every_employer

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue == "Yes")
        var pAttach = new GlideAjax('CheckAttachPRecodProducer');

    pAttach.addParam('sysparm_name', 'CheckAttachments');
    pAttach.addParam('sysparm_p_attach', g_form.getValue("p_attach"));
    pAttach.getXML(clientCallback);
}
function clientCallback(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer == 'yes') {
        return true;
    } else if (answer == 'no') {
        alert("You must attach document before submitting the form.");
        return false;
    }
}

 

 

need your help a bit desperately.  Please, and thank you!