Make attachment mandatory for a particular view?

Kiran Kumar 76
Tera Expert

we have multiple views created on a table

we need to make attachment mandatory in a particular view only and do not impact other,i know we can use view in client script ,i want to avoid using getxmlwait or gliderecord in client side

 

Any best practice to make attachment mandatory on a new record on submitting?

3 REPLIES 3

Community Alums
Not applicable

Hi @Kiran Kumar 76,

 

Write a on submit client script

 if (g_form.getViewName() === 'YourViewName') {
        var attachments = document.getElementById('header_attachment_list_label');
		if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
			alert('Please attach attachment.');
			return false;
		}
    }

 

Sai149_0-1716901628364.png

Tested in PDI.

 

I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

Hi @Community Alums 

 

Thanks tried on workspace ,isnt working

Community Alums
Not applicable

@Kiran Kumar 76 , I just tried in workspace...not sure why it's not working. But I used onsubmit client script & glideajax as an alternative & it's working in workspace (I tested on Service Operation Workspace). Please try the below

 

Script Include:

 

var aa = Class.create();
aa.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    hh: function() {
        var gr = new GlideRecord("sys_attachment");
        gr.addEncodedQuery("table_name=incident^table_sys_id="+this.getParameter('sysparm_id'));
        gr.query();
        if (gr.next()) {
            return true;
        } else {
            return false;
        }

    },

    type: 'aa'
});

 

Sai149_0-1716912559982.png

On submit client script:

 

function onSubmit() {
  if (g_form.getViewName() === 'YourViewName'){
    var ga = new GlideAjax('aa');
    ga.addParam('sysparm_name', 'hh');
	ga.addParam('sysparm_id',g_form.getValue('sys_id'));
    ga.getXMLAnswer(HelloWorldParse);
    return false;
  }
}

function HelloWorldParse(response) {
    // Handle the response
    alert(response);

    if (response === "false") {
       alert("Attach Attachment");
        return false;
    } else {
        
        return true;
    }
}

 

Sai149_0-1716912901566.png