UI Action Button Does not Submit the form

SuyashJ41731830
Tera Contributor

Hello,
I have a script include and a UI action Script

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

    getJiraProjects: function() {
        var projects = [
            { name: 'Project A', id: 'P-001', u_id: 'UID-001' },
            { name: 'Project B', id: 'P-002', u_id: 'UID-002' },
            { name: 'Project C', id: 'P-003', u_id: 'UID-003' }
        ];

        var result = [];

        for (var i = 0; i < projects.length; i++) {
            result.push({
                label: projects[i].name,
                value: projects[i].id
            });
        }

        return JSON.stringify(result);
    }

});




(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,
Suyash
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@SuyashJ41731830 

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.");
    });

}

AnkurBawiskar_0-1747658687217.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

JenniferRah
Mega Sage

In your UI Action, make sure the Client checkbox is checked and enter fetchAndPopulateProjects() in the onClick field.

Ankur Bawiskar
Tera Patron
Tera Patron

@SuyashJ41731830 

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.");
    });

}

AnkurBawiskar_0-1747658687217.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you so much it always work
@Ankur Bawiskar 

Community Alums
Not applicable

Hi @SuyashJ41731830 ,Based on what you've described, the issue is likely related to how the client script is structured and triggered. Since you're calling fetchAndPopulateProjects() immediately inside the UI Action script, and UI Actions don't directly allow async actions like getXMLAnswer() to finish properly when inline JavaScript is executed, the button can behave weirdly (including appearing unclickable or doing nothing).

 

Wrap the GlideAjax logic inside a named function and call it through the onclick field of the UI action instead of embedding the whole script inline.

 

try with this code  -script include

 

 var JiraProjectFetcher = Class.create();
JiraProjectFetcher.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getJiraProjects: function() {
        var projects = [
            { name: 'Project A', id: 'P-001', u_id: 'UID-001' },
            { name: 'Project B', id: 'P-002', u_id: 'UID-002' },
            { name: 'Project C', id: 'P-003', u_id: 'UID-003' }
        ];

        var result = [];
        for (var i = 0; i < projects.length; i++) {
            result.push({
                label: projects[i].name,
                value: projects[i].id
            });
        }

        return JSON.stringify(result);
    }
});

 

client 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.");
    });
}