- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2023 08:01 AM
Hi Community,
I placed a button component on my page in the UI builder. I've linked a page script with a handler function to it. Now when I click the button, I would like a server-side (not client side!) script include to be called. I don't find anything in the handler function API that would allow me to make such a call.
What I've tried so far:
- firing a UX client side script include and firing a GlideAjax inside of it
- GlideAjax API not available in the handler functions
- UX Events don't seem to allow for a UI-Builder-independent server side processing
The only alternative I see is making API calls to start a Flow and running my server code in it, but it is a very cumbersome solution, not elegant at all...
Any hints?
#workspace #UIBuild #UIB
@Brad Tilton
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2023 06:15 AM
Any data handling in UIB, whether pulling data or writing data, should be handled through data resources. There are update record and create record data resources you can use for simple updates, or you can create your own GraphQL or REST data resources. The last resort would be to create a transform data resource to execute some server side code.
There is also an http helper function documented on the dev site you can use to consume a REST API from a script, but you should really try to use data resources.
This post may help out: https://www.servicenow.com/community/next-experience-articles/all-about-data-resources-in-ui-builder...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2023 06:15 AM
Any data handling in UIB, whether pulling data or writing data, should be handled through data resources. There are update record and create record data resources you can use for simple updates, or you can create your own GraphQL or REST data resources. The last resort would be to create a transform data resource to execute some server side code.
There is also an http helper function documented on the dev site you can use to consume a REST API from a script, but you should really try to use data resources.
This post may help out: https://www.servicenow.com/community/next-experience-articles/all-about-data-resources-in-ui-builder...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 06:58 AM
Could you share more about what you're looking to achieve here? The flow+scripted rest api+rest data resource+script seems overly complex depending on what your real use case is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 07:07 AM
I would like to click the Transform button and launch a function from a Script Include, not passing any parameters. The fired function should return a sys_id. This sys_id would then be used to update the state.
Currently the solution posted below by Bart is used, but if there's a shorter one - we'd gladly try it.
If that'd help - the purpose of the function is to grab an attachment from a data source record, create an import set with the data from the attachment and transform it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2023 07:05 AM
You could just write a transform data resource that calls your script include, and then execute it on the button click. You can return the sys_id as part of the transform data resource's payload, then write it to the state on the transform data resource's success event. Note that any time you create a new transform data resource it needs a corresponding ACL.