- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 10:35 AM
User can submit a request only if attachment is attached on catalog form?
I dont want to do with catalog client script.
How to do this validation ?
I need a code for client script and script include.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2019 08:33 AM
Hello Nidhi,
Check out this code. This will definitely work. Though this script has some limitations.
Client script Code:
function onSubmit() {
// var formID = gel('sysparm_item_guid').value;
// var formID= document.getElementById('sysparm_item_guid').value;
var formID = g_form.getValue('sysparm_item_guid');
alert("Form ID: "+formID);
var ab = new GlideAjax('global.hasAttachment');
ab.addParam('sysparm_name', 'attachment');
ab.addParam('sysparm_form_data', formID);
ab.getXMLWait();
var isTrue = ab.getAnswer();
alert("Result From Scrit Include: "+isTrue);
if(isTrue == 'yes'){
alert("Kudos to you!! You have added attachment");
return true;
}
else if(isTrue == 'no'){
alert("You must attach document before submitting the form.");
return false;
}
Script include Code:
var hasAttachment = Class.create();
hasAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
attachment: function(){
var dataCheck = this.getParameter('sysparm_form_data');
gs.log("AG formID"+dataCheck);
var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_name', "sc_cart_item");
gr.addQuery('table_sys_id', dataCheck);
gr.query();
if (gr.next()) {
gs.log("Kudos to you!! You have added attachment ");
return 'yes';
}
else{
gs.log("You must attach document before submitting the form.");
return 'no';
}
},
type: 'hasAttachment'
});
getXMLWait()
Sends the server a request to execute the method and parameters associated with this GlideAjax object.
The server processes the request synchronously and will not process further requests from the client until finished. To retrieve the results, the client must call getAnswer(). Using getXMLWait() ensures the order of execution, but can cause the application to seem unresponsive, significantly degrading the user experience of any application that uses it. We recommend using getXML() instead.
Note: getXMLWait() is not available to scoped applications.
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 10:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 10:51 AM
Can i do with client side and with script include ?
I am learning so want to know how to code ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 10:54 AM
You said you don't want to do it with a client script...then ask for client script.
If you want to learn how...then you can search the forums as this question is asked quite a lot.
So there's plenty of posts about it if you don't want to use the method sachin posted.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2019 10:55 AM
Can you send me the links of those post that you feel are correct for this question?