How to make mandatory attachment in RITM before submitting it

Gayathree Seeth
Tera Expert

Hi,

My requirement is After making the approval field as approved, it should ask for the mandatory attachment and then only i should be able to submit the RITM

 

I have tried using the Script include and calling it in client script as below:

Script include:

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

checkAttachment: function(){
var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_name', 'sc_req_item');
gr.query();
if (gr.next()) {
return 'yes';
}
else{
return 'no';
}
},
type: 'CheckAttachmentCatalogItem'
});

 

Client Script:

function onSubmit() {
//Type appropriate comment here, and begin script below

var demo = new GlideAjax('CheckAttachmentCatalogItem');
demo.addParam('sysparm_name', 'checkAttachment');
demo.getXMLWait();
var ap=g_form.getValue("approval");
if(ap=='approved')
{
alert('test');

var attachment=demo.getAnswer();
if(attachment == 'yes')
{
return true;
}
if(attachment == 'no')
{
alert("Please attach attachment");
return false;
}
}
}

When i use this code it is not checking for the attachment.

Please suggest the code according to my scenario.

1 ACCEPTED SOLUTION

@Gayathree Seeth 

Ok,  i got your  requirement-

You have to pass record id as well ,update your script include function and client script code as below-

 

var CheckAttachmentCatalogItem = Class.create();

CheckAttachmentCatalogItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkAttachment: function(){

var recordID = this.getParameter('sysparm_id');

var gr = new GlideRecord("sys_attachment");

gr.addQuery('table_name', 'sc_req_item');

gr.addQuery('table_sys_id',recordID);

gr.query();

if (gr.next()) {

return 'yes';

}

else

{

return 'no';

 

}

},

type: 'CheckAttachmentCatalogItem'

});

 

Client Script:

function onSubmit() {

//Type appropriate comment here, and begin script below

var id = g_form.getUniqueValue();//this give sys_id of ritm record

var demo = new GlideAjax('CheckAttachmentCatalogItem');

demo.addParam('sysparm_name', 'checkAttachment');

demo.addParam('sysparm_id, id);

demo.getXMLWait();

var ap=g_form.getValue("approval");

var attachment=demo.getAnswer();

 

if(ap=='approved')

{

alert('test'); if(attachment == 'yes') {

return true;

}

if(attachment == 'no')

{

alert("Please attach attachment");

return false;

}

}

}

Add info or error message instead of alert

g_form.addErrorMessage('Please attach attachment');

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha Bangale

View solution in original post

4 REPLIES 4

manjusha_
Kilo Sage

@Gayathree Seeth 

 

To make attachment mandatory before a request gets submitted ,there is Out of the box functionality which you can utilise

Go to  your catalog item>Portal Settings>Mandatory attachment checkbox-mark this check box as selected 

 

So ,when ever you a submit a request an error message will be thrown for attachment ,this will work only for portal only

Use below screenshot for reference-

manjusha__0-1681141184483.png

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

hi Manju,

thanks for response.

Actually my requirement is different, I want to attach an attachment at the ritm record.

When the approval field is changed to approved, then it should ask for the attachment and then only it should allow me to submit the RITM form.

 

GayathreeSeeth_0-1681142106072.png

 

@Gayathree Seeth 

Ok,  i got your  requirement-

You have to pass record id as well ,update your script include function and client script code as below-

 

var CheckAttachmentCatalogItem = Class.create();

CheckAttachmentCatalogItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkAttachment: function(){

var recordID = this.getParameter('sysparm_id');

var gr = new GlideRecord("sys_attachment");

gr.addQuery('table_name', 'sc_req_item');

gr.addQuery('table_sys_id',recordID);

gr.query();

if (gr.next()) {

return 'yes';

}

else

{

return 'no';

 

}

},

type: 'CheckAttachmentCatalogItem'

});

 

Client Script:

function onSubmit() {

//Type appropriate comment here, and begin script below

var id = g_form.getUniqueValue();//this give sys_id of ritm record

var demo = new GlideAjax('CheckAttachmentCatalogItem');

demo.addParam('sysparm_name', 'checkAttachment');

demo.addParam('sysparm_id, id);

demo.getXMLWait();

var ap=g_form.getValue("approval");

var attachment=demo.getAnswer();

 

if(ap=='approved')

{

alert('test'); if(attachment == 'yes') {

return true;

}

if(attachment == 'no')

{

alert("Please attach attachment");

return false;

}

}

}

Add info or error message instead of alert

g_form.addErrorMessage('Please attach attachment');

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha Bangale

Thanks Very much Manju!!

Really helped.