making attachment mandatory

engLiShpIlla
Tera Contributor

I am working on a catalog item and it has a question with type select box where we can select a specific item from drop down

we are managing attachments from portal settings we have mandatory_attachment check box we can select to make attachment mandatory

but I want to make attachments mandatory based on the select box answer dynamically 

how can I do that

when I check dictionary of mandatory_attatchment it is showing True/False type

 

solutions tried:

tried with both Ui policies and client scripts

g_form.setMandatory('mandatory_attachment', true);

something similar to this 

g_form.setValue('mandatory_attachment', true);

1 REPLY 1

Brian Lancaster
Tera Sage

There are two ways to do this. Both you would not use the mandatory checkbox so set it to false for that catalog item.

1. User a variable of type attachment and make that mandatory.

2. Use a client scrip to check for attachments it would be an on submit client script. If you use the service portal you will need to add a script there two. There is a drawback to this option as it will not work for the mobile client if you are using that.

 

Steps for option 2.

1. Go into the Service Portals theme and add a JS include named GlobalCatalogItemFunctions. In the script section create a scrip with the same name and the following code.

 

 

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

 

 

2. In your catalog item create an onsubmit client scrip and make sure the attachment is there. You will need to make sure that the client script has the field called Isolate script set to false. This field is not on the form by default. UI Type will need to be set to all as well.

 

 

var varialbe = g_form.getValue('variable_name');
if (variable == 'variable_value') {
    try { //non Service Portal
        var attachments = document.getElementById('header_attachment_list_label');
        if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
            alert('Message about attchment need to be included');
            return false;
        }
    }

    //For Service Portal
    catch (e) {
        var count = getSCAttachmentCount();
        if (count <= 0) {
            alert('message about attachment needing to be included');
            return false;
        }
    }
}