We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

clicking on new button in related list gives an alert : failed to execute action

Shivani4532
Tera Contributor

In the service operations workspace, in related list -  child incidents, related records tab, there is a new button.
We have to customize the button in such a way that it opens a modal pop up with 3 options in the dropdown. Based on the user selection, it has redirect them to specific catalog item.

I have tried using declarative actions, which I implemented as client script.

Shivani4532_0-1770837282909.png



However, when I try to click on New1 button in workspace it gives an alert. "Failed to execute action. Please contact system administrator"

Shivani4532_2-1770837489989.png

 

Shivani4532_1-1770837438227.png

Modal shows up as expected on the New1 button click.  However, we are able to see the alert behind it.

I'm looking for some guidance on this. Any help would be really appreciated.


7 REPLIES 7

Bhavya11
Kilo Patron

Hi @Shivani4532 ,

 

Check the below KB to debug:

How to troubleshoot UI Actions either or not showing or not working 

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

Ankur Bawiskar
Tera Patron

@Shivani4532 

share the client script as well which you wrote.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar , here is my client script

(
function(params) {
    // We use a small delay to let the 'return true' finish first
    setTimeout(function() {
        try {
            // Get Parent ID from params
            var parentId = params.parent_sys_id || params.sys_id;
           
            if (!parentId && typeof g_form !== 'undefined') {
                parentId = g_form.getUniqueValue();
            }

            g_modal.showFields({
                title: "Create Incident Task",
                fields: [{
                    type: "choice",
                    name: "task_type",
                    label: "Select Task Type",
                    mandatory: true,
                    choices: [
                        { displayValue: "Normal Incident Task", value: "normal" },
                        { displayValue: "password reset", value: "password_reset" },
                        { displayValue: "Group access", value: "group_access" }
                    ]
                }]
            }).then(function(modalResult) {
                if (!modalResult || !modalResult.updatedFields) return;

                var selectedOption = modalResult.updatedFields[0].value;

                // Handle routing based on selection
                if (selectedOption === "normal") {
                    g_aw.openRecord('incident_task', '-1', {
                        query: 'incident=' + parentId
                    });
                } else if (selectedOption === "password_reset") {
                    openCatItem("29a39e830a0a0b27007d1e200ad52253", parentId);
                } else if (selectedOption === "group_access") {
                    openCatItem("f0caa23e97c2019021983d1e6253af9a", parentId);
                }
            });
        } catch (e) {
            console.error("Modal Script Error:", e);
        }

        function openCatItem(sysId, pId) {
            // Using the Workspace-safe way to open catalog items
            if (typeof g_service_catalog !== 'undefined') {
                g_service_catalog.openCatalogItem('sc_cat_item', sysId, {
                    sysparm_parent_table: 'incident',
                    sysparm_parent_sys_id: pId
                });
            }
        }
    }, 50);

    
    return true;
})(this);

@Shivani4532 

is it giving error to admin as well?

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