Uncaught ReferenceError: is not defined at HTMLButtonElement.onclick

sadiq
Tera Contributor

Hello guys I am trying to download the pdf format but unknowingly I get this error as Uncaught ReferenceError:

downloadIncident() is not defined at HTMLButtonElement.onclick 

did anyone face this issue while working on UI pages?
1 ACCEPTED SOLUTION

HI @sadiq ,

I tried this code as is and it is working fine for me, no issue with code in my PDI. Please try this once in your PDI, if it is working in PDI, may be your organization instance is blocking some external scripts.

 

AnveshKumarM_0-1695295360869.png

 

Thanks,
Anvesh

View solution in original post

8 REPLIES 8

AnveshKumar M
Tera Sage
Tera Sage

Hi @sadiq 

In the UI Page have you defined the function downloadIncident() in client script, as per the error message there is no such function available.

 

Please let me know if you need more help!

 

Thanks,
Anvesh

This is the UI page HTML :
<
?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<h3>Get incident Data</h3>
 
<input class="form-control" type="text" id="incident1" value=""></input>

 

 
<button id="inco" onclick="elon1()" style="color: white; background-color: #183D3D; font-weight: bold">Download</button>
</j:jelly>

this is the client script:

window.jsPDF = window.jspdf.jsPDF;

function elon1() {
var doc = new jsPDF();
var incNumber = document.getElementById('incident1').value; // Corrected element ID access
 


var ga = new GlideAjax('genIncDetails');
ga.addParam('sysparm_name', 'incData');
ga.addParam('sysparm_number', incNumber);
ga.getXML(rob);

function rob(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var result = JSON.parse(answer);

// Use doc.text correctly with parentheses
doc.text(20, 30, 'incident_number: ' + result.number);
doc.text(20, 40, 'incident_name: ' + result.name);
doc.text(20, 50, 'incident_short_desc: ' + result.short_desc); // Use 'result.short_desc' instead of 'result.short_description'
doc.text(20, 60, 'incident_state: ' + result.state);
doc.save(result.number + '.pdf');
}
}
this is the script include :

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

incData: function() {
var ind = this.getParameter('sysparm_number');
var gd = new GlideRecord('incident');
gd.addQuery('number', ind);
gd.query();
var o = {};
if (gd.next()) {
o.number = gd.number.getDisplayValue();
o.name = gd.name.getDisplayValue();
o.short_desc = gd.short_description.getDisplayValue();
o.state = gd.state.getDisplayValue();
 


} else {
return null;
}
return JSON.stringify(o);




},



type: 'genIncDetails'
});

Could you please help. I dont understand why I am getting the error.

HI @sadiq ,

I tried this code as is and it is working fine for me, no issue with code in my PDI. Please try this once in your PDI, if it is working in PDI, may be your organization instance is blocking some external scripts.

 

AnveshKumarM_0-1695295360869.png

 

Thanks,
Anvesh

Hey anveshkumar M thank you so much for this! will definitely try in a different browser or different instance! thank you once again!