- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 12:07 AM
Hello,
I have a script include and a UI action Script
(function fetchAndPopulateProjects() {
var ga = new GlideAjax('JiraProjectFetcher');
ga.addParam('sysparm_name', 'getJiraProjects');
ga.getXMLAnswer(function(response) {
var projects = JSON.parse(response);
if (projects.length === 0) {
alert('No Jira projects returned.');
return;
}
g_form.clearOptions('u_project_name');
g_form.addOption('u_project_name', '', '-- Select a project --');
for (var i = 0; i < projects.length; i++) {
g_form.addOption('u_project_name', projects[i].value, projects[i].label);
}
alert("Jira project options loaded.");
});
})();
The issue is when i click in the button the button is not clicked / unclickable.
I need to test the script that it is fetching value from the script include and populating in the field
Thanks, and Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 05:44 AM
share your UI action configuration screenshot
since you are using Client Side UI action make sure this
1) client checkbox - true
2) Onclick function - fetchAndPopulateProjects()
3) Script field as this
function fetchAndPopulateProjects() {
var ga = new GlideAjax('JiraProjectFetcher');
ga.addParam('sysparm_name', 'getJiraProjects');
ga.getXMLAnswer(function(response) {
var projects = JSON.parse(response);
if (projects.length === 0) {
alert('No Jira projects returned.');
return;
}
g_form.clearOptions('u_project_name');
g_form.addOption('u_project_name', '', '-- Select a project --');
for (var i = 0; i < projects.length; i++) {
g_form.addOption('u_project_name', projects[i].value, projects[i].label);
}
alert("Jira project options loaded.");
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 05:57 AM
Hi @SuyashJ41731830,
Step-by-Step Fix
1. Change the Script to a Click Handler
You currently have this:
(function fetchAndPopulateProjects() {
var ga = new GlideAjax('JiraProjectFetcher');
...
})();
This is an IIFE (Immediately Invoked Function Expression) — it runs as soon as the UI Action loads, not on button click.
Fix: Define a named function instead:
function fetchAndPopulateProjects() {
var ga = new GlideAjax('JiraProjectFetcher');
ga.addParam('sysparm_name', 'getJiraProjects');
ga.getXMLAnswer(function(response) {
var projects = JSON.parse(response);
if (projects.length === 0) {
alert('No Jira projects returned.');
return;
}
g_form.clearOptions('u_project_name');
g_form.addOption('u_project_name', '', '-- Select a project --');
for (var i = 0; i < projects.length; i++) {
g_form.addOption('u_project_name', projects[i].value, projects[i].label);
}
alert("Jira project options loaded.");
});
}
2. UI Action Configuration
In the UI Action record, set:
Field Value
Name Fetch Projects
Table [Your table name]
Action name fetch_projects
Form button (checked)
Client (checked)
Script fetchAndPopulateProjects();
3. Script Include Configuration
Make sure the Script Include is:
Accessible from client scripts:
Check Client Callable
Name exactly: JiraProjectFetcher
Extends AbstractAjaxProcessor ( you already have)
Result
Once you make the above changes:
The button will appear on the form.
When clicked, it will fetch Jira projects from the Script Include via GlideAjax.
It will populate the dropdown field u_project_name.
Thanks and Regards,
Chiranjeevi R
Please mark as Correct Answer/Helpful, if applicable.
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.