Hi I want to validate if attachment is attached before submitting catalog request

Nidhi6
Giga Contributor

Hi,

I have written catalog script and script include. While submitting form without checking attachment the form is getting submitted.

Screenshots of client script and Script Include is attached below: 

Please help me where my code is getting wrong.

find_real_file.png

 

 

find_real_file.png

 

 

1 ACCEPTED SOLUTION

Just give me 10 minutes, I am doing corrections

Thank you,
Abhishek Gardade

View solution in original post

9 REPLIES 9

Yes u added "" and i also did active script.Yet request is getting submitted

I have tested the similar code and its working. Can you paste a code? Dont paste a screenshot.

 

Thank you,
Abhishek Gardade

var checkattachment = Class.create();
checkattachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
attachment: function(){
var check = this.getParamater('sysparam_ga');
if(check == 'true'){
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
gs.addInfoMessage("You must attach document before submitting the form.");
return false;
}
}
},

type: 'checkattachment'

});

 

function onSubmit() {

var ga = g_form.getValue('sysparm_item_guide');
var ab = new GlideAjax('checkattachment');
ab.addParam('sysparm_name', "attachment");
ab.addParam('sysparm_ga', ga);
ab.getXML(checking);
function checking(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == true){
return true;
}else if(answer == false){
return false;
}
}
}

Just give me 10 minutes, I am doing corrections

Thank you,
Abhishek Gardade

Alright!