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.

Nidhi6
Giga Contributor

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.

1 ACCEPTED SOLUTION

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

      

Thank you,
Abhishek Gardade

View solution in original post

7 REPLIES 7

sachin_namjoshi
Kilo Patron
Kilo Patron

You don't need code for attachment validation.

USe below flag on catalog item

 

find_real_file.png

 

Regards,

Sachin

Can i do with client side and with script include ?

I am learning so want to know how to code ?

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!

Can you send me the links of those post that you feel are correct for this question?