- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 07:18 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 11:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 08:40 AM
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-
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 08:55 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 11:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 03:24 AM
Thanks Very much Manju!!
Really helped.