Client script in scoped application is not executing the script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 11:03 AM
The requirement is to create the pop up dialog box with all the attachments that the HR case form has when ever the handover checkbox is checked.
I have written the on change client script and called the script include using glide ajax. It is showing all the alerts from client script but not giving any logs from the script include.
Any help is appreciated.
client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// var confirm_box = confirm("Confirm Box");
if (newValue.toString() == 'true') {
alert("HJ newValue---" + newValue);
var recordSysId = g_form.getUniqueValue();
alert("HJ recordSysId---" + recordSysId);
var tableName = g_form.getTableName();
alert("HJ tableName---" + tableName);
//Initialize and open the Dialog Window
// var dialog = new GlideDialogWindow("confirm_dialog");
// dialog.setTitle("Add Attachment to handover"); //Set the dialog title
//var attach = new GlideAjax('sys_attachments');
var attach = new GlideAjax('BICheckAttachment'); //BICheckAttachment
alert("HJ Attach");
attach.addParam('sysparm_name', 'getAttachmentsFromForm');
attach.addParam('sysparm_id', recordSysId);
attach.addParam('sysparm_table', tableName);
attach.getXML(fill);
function fill(response) {
alert("HJ Response-" + response);
var answer = response.responseXML.documentElement.getAttribute("answer");
var dialog = new GlideDialogWindow("confirm_dialog");
dialog.setTitle("Add Attachment to handover"); //Set the dialog title
dialog.setPreference("target_sys_id", answer);
dialog.setPreference("target_table", tableName);
dialog.setSize(500, 500);
dialog.render(); //Open the dialog
}
}
}
script include - accessible from all application scopes is selected.
var BICheckAttachment = Class.create();
BICheckAttachment.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getAttachmentsFromForm: function()
{
gs.info("HJ CHECK IN SCRIPT INCLUDE");
var answer= [];
var id = this.getParameter('sysparm_id');
gs.info("HJ ID--"+id);
var value = this.getParameter('sysparm_table');
gs.info("HJ value--"+value);
var grat= new GlideRecord('sys_attachment');
grat.addQuery("table_sys_id",id);
grat.addQuery("target_table", value);
grat.query();
while(grat.next())
{
gs.info("HJ--grat"+grat.next());
answer.push(grat.sys_id.toString());
}
gs.info("HJ Answer"+answer);
return 'sys_idIN' + answer.join(",");
},
type: 'BICheckAttachment'
});
End result should be as below - I achieved it once but without changing anything it is not working again. Dont know how it worked earlier
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:05 PM
I created cross scoped privilege application. Script include is getting called.
from below line it did not execute
var grat= new GlideRecord('sys_attachment');
what ever the logs in id and value are available in attachment table still it didnot query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:09 PM
Hi,
Did you check any query BR on sys_attachment is restricting it?
you are querying with incorrect field?
var BICheckAttachment = Class.create();
BICheckAttachment.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getAttachmentsFromForm: function()
{
gs.info("HJ CHECK IN SCRIPT INCLUDE");
var answer= [];
var id = this.getParameter('sysparm_id');
gs.info("HJ ID--"+id);
var value = this.getParameter('sysparm_table');
gs.info("HJ value--"+value);
var grat = new GlideRecord('sys_attachment');
grat.addQuery("table_sys_id",id);
grat.addQuery("table_name", value);
grat.query();
while(grat.next())
{
// gs.info("HJ--grat"+grat.next()); // comment this line
answer.push(grat.sys_id.toString());
}
gs.info("HJ Answer"+answer);
return 'sys_idIN' + answer.join(",");
},
type: 'BICheckAttachment'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:17 PM
still it is returning the httpobject to client script
Answer is having the value but not returing it to the client script
var BICheckAttachment = Class.create();
BICheckAttachment.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getAttachmentsFromForm: function()
{
gs.info("HJ CHECK IN SCRIPT INCLUDE");
var answer= [];
var id = this.getParameter('sysparm_id');
gs.info("HJ ID--"+id);
var value = this.getParameter('sysparm_table');
gs.info("HJ value--"+value);
var grat= new GlideRecord('sys_attachment');
grat.addQuery("table_sys_id",id);
grat.addQuery("table_name", value);
grat.query();
while(grat.next())
{
gs.info("HJ--grat"+grat.next());
answer.push(grat.table_sys_id.toString());
}
gs.info("HJ Answer"+answer);
return 'sys_idIN' + answer.join(",");
},
type: 'BICheckAttachment'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:23 PM
now 1st part is resolved i.e. you are able to query
you are sending the query with sys_ids but not passing it to UI page?
what needs to be shown on UI page?
can you share the UI page HTML, client script etc
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:27 PM
I dinot create any UI Pages, I used glide dialog window in client script.
it should show the all the attachments from HR Case Record to the pop up box with check to select and remove or to save the attachments