Not able to call script inlcude
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 03:32 AM
I am trying to call script inlcude by onchange client script but i am not able to do so...but are in scoped application
script include:
var CheckForDuplicity = Class.create();
CheckForDuplicity.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkForDuplication: function() {
gs.log('working','working12');
var invoiceNumber = this.getParameter('sysparm_invoiceNo');
var invoiceAmount = this.getParameter('sysparm_invoiceAmount'); // Updated parameter name
var invoiceDate = this.getParameter('sysparm_invoiceDate'); // Updated parameter name
var vendorCode = this.getParameter('sysparm_vendorCode'); // Updated parameter name
// Logging the values for debugging
gs.log('Invoice Number: ' + invoiceNumber, 'CheckForDuplicity');
gs.log('Invoice Amount: ' + invoiceAmount, 'CheckForDuplicity');
gs.log('Invoice Date: ' + invoiceDate, 'CheckForDuplicity');
gs.log('Vendor Code: ' + vendorCode, 'CheckForDuplicity');
var gr = new GlideRecord('x_perii_account_0_marketing_invoice');
gr.addQuery('invoice_no', invoiceNumber);
gr.addQuery('invoice_amount', invoiceAmount);
gr.addQuery('invoice_date', invoiceDate);
gr.addQuery('vendor_code', vendorCode);
gr.query();
if (gr.next()) {
gs.log('Duplicate record found.', 'CheckForDuplicity');
return 'true'; // Return as string for client-side
} else {
gs.log('No duplicate record found.', 'CheckForDuplicity');
return 'false'; // Return as string for client-side
}
},
type: 'CheckForDuplicity'
client script:
var invoiceNumber = g_form.getValue('invoice_no');
var invoiceDate = g_form.getValue('invoice_date');
var invoiceAmount = g_form.getValue('invoice_amount');
var vendorCode = g_form.getValue('vendor_code');
// Alert concatenated values
alert('Invoice Number: ' + invoiceNumber + ', Vendor Code: ' + vendorCode + ', Invoice Date: ' + invoiceDate);
// Create GlideAjax object
var ga = new GlideAjax('CheckForDuplicity');
ga.addParam('sysparm_name','checkForDuplication');
ga.addParam('sysparm_invoiceNo', invoiceNumber);
ga.addParam('sysparm_invoiceAmount', invoiceAmount); // Fixed parameter name
ga.addParam('sysparm_invoiceDate', invoiceDate); // Fixed parameter name
ga.addParam('sysparm_vendorCode', vendorCode); // Fixed parameter name
alert('test');
// Send request and handle response
ga.getXMLAnswer(duplicate);
function duplicate(response) {
response = response.trim(); // Trim whitespace
if (response === 'true') {
g_scratchpad.duplicateRecord = 'false';
} else {
g_scratchpad.duplicateRecord = 'true';
}
}
script include is not triggering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 03:38 AM
Hello @gautam_dhamija ,
Since you're in a scoped application, ensure that your Script Include is accessible by client-side code:
- Make sure the CheckForDuplicity Script Include has the "Client Callable" checkbox checked.
- Verify that your Script Include is in the same scope as the client script.
var invoiceNumber = g_form.getValue('invoice_no');
var invoiceDate = g_form.getValue('invoice_date');
var invoiceAmount = g_form.getValue('invoice_amount');
var vendorCode = g_form.getValue('vendor_code');
// Create GlideAjax object
var ga = new GlideAjax('CheckForDuplicity');
ga.addParam('sysparm_name', 'checkForDuplication');
ga.addParam('sysparm_invoiceNo', invoiceNumber);
ga.addParam('sysparm_invoiceAmount', invoiceAmount);
ga.addParam('sysparm_invoiceDate', invoiceDate);
ga.addParam('sysparm_vendorCode', vendorCode);
// Send request and handle response
ga.getXMLAnswer(duplicate);
function duplicate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer === 'true') {
alert('Duplicate record found');
} else {
alert('No duplicate record found');
}
}
Please let me know your views on this one & Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 03:46 AM
Can you try calling GlideAjax with the scope of a script include ( write the api name of script include)
Also please make sure that client callable is checked for your script include
For example
var ga= new GlideAjax('global.CheckForDuplicity'); //if script include is in global scope
Thanks & Regards
Sejal Chavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 03:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 03:58 AM
Is your Script Include Accessible from All application scopes?
Do you have anything listed in the Access Control Related List? This usually includes a role that has access to the script, that is prompted when the Script Include is created.
Also check to make sure you don't have any other Script Includes with the same name.