Using GlideAjax from UI Action but still waiting for "Running Transaction"

jfvalenzuelas
Kilo Contributor

Hello everybody,

A little bit of context

I have added a new UI Action as a List Choice and marked the "Client" checkbox so it becomes client side.

For this UI Action, I have added also a function to be called onClick. This function is defined in the Script part of the UI Action.

Let's call the Function initialLoad(), but what does it do?

This function basically calls a server-side script using GlideAjax to do some processing so the user can use the browser normally. The server-side script triggers some SOAP Messages to receive data from other systems and create new records with the information contained in the response.

UI Action

 

 

 

function load() {
    var ga = new GlideAjax('LNXT_AjaxUtils');
    ga.addParam('sysparm_name', 'initialLoad');
    ga.addParam('sysparm_selectedIds', g_list.getChecked());

    ga.getXML(getAnswer);
}

function getAnswer(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
}

Server-side Script

Here we are extending with AbstractAjaxProcessor and of course, we have the initialLoad() function as well.

With this function, we are basically triggering further logic form other scripts includes but all of this should happen on the server-side.

The problem

When I trigger this functionality with the UI Action, the browser still makes me wait for a "Running Transaction" and of course, this is not the desired behavior. Currently, I still have to wait for the server-side to finish and the idea is that all this logic runs in the background while we are still able to use the browser and do some other stuff in the meantime.

Has anybody any experience with something like this?

Has anybody experienced using GlideAjax but still have to wait for a "Running Transaction"?

 

Thanks for your time!

Jaime

1 ACCEPTED SOLUTION

DScroggins
Kilo Sage

Hi Jaime. We have run into this before where the async GlideAjax call was not returning until the script had finished processing. We ultimately ended up creating events and script actions to process the data all while allowing a speedy return of control back to the client. So you could have your process logic in a normal script include and use an event to call said logic. The GlideAjax call would add the event to the event queue then return to the user. The event queue would then process the event and execute your logic. Hope this helps. --David

View solution in original post

4 REPLIES 4

Kieran Anson
Kilo Patron

Hi Jaime,

Could you explain the objective of this UI action a bit more? Is there a reason it's a UI action over an async business rule which might provide better performance.

Also, if the UI action is client callable, you can run both client & server code within a UI action without needing to do GlideAjax

https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

Hi Kieran, thanks for your reply! The goal of this is to call a function that triggers SOAP messages with a third system to import information. This UI Action triggers an Initial Load but we don't want to wait for this to be done in order to continue working in the browser. We have already solved it and it was basically the same idea that David commented in another comment.

DScroggins
Kilo Sage

Hi Jaime. We have run into this before where the async GlideAjax call was not returning until the script had finished processing. We ultimately ended up creating events and script actions to process the data all while allowing a speedy return of control back to the client. So you could have your process logic in a normal script include and use an event to call said logic. The GlideAjax call would add the event to the event queue then return to the user. The event queue would then process the event and execute your logic. Hope this helps. --David

Hi David, Sadly the question took too long to be posted but we figured out the same that you describe. We ended up triggering and event via the UI Action giving as parameter the sys_id of the current record. On this event, a script action calls our function from a script include and everything runs in server side, leaving the browser free for the user to continue interacting. I think this is the best approach for it and hopefully someone else would be able to use this solution.

 

Thank you for your reply!