Action Assignment Implemented as Client Script

Daniel67
Tera Contributor

Hello,

 

has anyone played with Action Assignments implemented as a Client Script? I am trying to create a list action (to update records on list) using g_modal.showFields. Yet, I am having a problem with calling Ajax script from the client script (it looks like it is not running at all).

 

I am trying to run the ajax call at the beginning of the script (I need to fetch some values from server to be placed as options on modal) - in this case modal is loaded but script include is not triggered (all the script include does for the moment is printing info to logs to verify it is triggered).

 

I am also trying to call it after after modal confirmation ( inside ".then(function(fieldValues) {}');

) - in this case nothing happens when clicking the button on the list.

 

What am I missing? Or is it not possible to call server from Action Assignment implemented as Client Script?

 

Action Assignment config:

Screenshot_1.png

Client Script:

function onClick() {
 
    var checked = g_list.getChecked();
    var rowsArray = new Array();
    rowsArray = checked.split(",");
 
    var ga = new GlideAjax("sn_customerservice.CSMAjaxUtils");
    ga.addParam("sysparm_name", "testFunction");
    ga.addParam("sysparm_case_id", 'd0e4a02e87f9a190a94feb509bbb358e');
    //closeDialog();
    var response = ga.getXML(ajaxResponse);
 
    function ajaxResponse(serverResponse) {
 
   }
 
 
    var fields = [{
            type: 'textarea',
            name: 'work_notes',
            label: getMessage('Resolution notes'),
            mandatory: true
        },
        {
            type: 'choice',
            name: 'causing_party',
            label: getMessage('Causing party'),
            value: getMessage(' -- Select -- '),
            choices: [{
                    displayValue: 'Duplicate',
                    value: 'duplicate'
                },
                {
                    displayValue: 'Canceled',
                    value: 'canceled'
                }
            ],
            mandatory: true
        }
    ];
 
    g_modal.showFields({
        title: "Enter your reason",
        fields: fields,
        size: 'lg'
    }).then(function(fieldValues) {
 
    });
}
4 REPLIES 4

Anil Lande
Kilo Patron

Hi,

You can call Server Side Script from Action assignment.

Make sure your Script include is client callable and you are passing correct function name.

You can check OOB Action assignments calling GlideAjax. Try adding some logs in your Client side script and make sure it is reaching GlideAjax part. 

Try commenting some initial lines and see if any API is not supported gere.

 

below OOB actions is using glideAjax, that means it is supported.

Screenshot 2023-05-30 at 5.58.14 PM.png

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi,

thank you. It helped me, to some extent, as I reviewed all the code again. I found nothing (script include is client callable, no spelling errors, etc.) except that my script include was in scope that is not accessible. I moved the script to Global and now it works, but only partially.

 

When I call the script at the beginning of Client Script - it works perfectly.

But - when I move the same script to '.then' function of g_mode.showFields() (as in any OOB Workspace Client Script where some server side actions are run after user clicks OK button) then list action button does nothing (except reporting "Error while running Client Script "GlideScopedScript": TypeError: Cannot read properties of undefined (reading 'apply')" in console log).

Daniel67_0-1685525624857.png

What is more, when I remove calling GlideAjax from '.then' function, nothing changes - button still does not react. It works again only after I revert Action Assignment record to previous versions.

 

Any ideas?

 

Best regards

Daniel

Rapunzel
Tera Contributor

I had the same problem, being unable to call a Script Include, nor from an "Action Assignment" (a List Action), nor from a UI Action (both for Scoped Apps / Workspaces - one button on a record form, the other on the List view.

 

I solved this this way =>

- Providing the whole "API Name" of the Script include into the Ajax Call

- Changing the "Accessible from" field, in the Script include, from "This application Scope only" to "All application scopes".

 

I have no idea why it's working now, because all records (Action assignment, UI action, Script Include) all belong to the same Scoped app.

But well... It seems that the Ajax call was happening in the Global scope, for some reason. Hence, this solution. 🙂

Thanks Bro it Worked Beautifully!!