Please help with UI Action script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:09 PM
Hello,
I am using UI action function to call server side code to update records (Only for test purposes).
Is it possible to use the "else" statement to call different server side code. If not, please provide suggestions.
Thank you
Here is the example code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:45 PM
@Jessica28 , You cannot Call BR directly in UI Action , if you want to Run script which has on Business just Bring the Code and Enter into Server Side Script in UI Action
Suggestion 2
You can design Script Include and Include your BR code In it and you can call into UI Action with following Syntax
new ScriptIncludename().function(); //Pass your SI name and Functionname
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:41 PM
Hi @Jessica28
Better to call script include function instead of calling server side code under if else loop.
You can see the below OOB code for your reference.
/sys_ui_action.do?sys_id=f7b7a87a0f69111048d04abec4767e1a
Please Mark this Helpful and Accepted Solution if it solves your issue.
Thanks & Regards,
Shikha Tyagi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:46 PM
Hi @shikhatyagi
Thank you for your suggestion. However, I did not understand how to use script include function to call server side code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 12:46 AM
Hi @Jessica28
Please use below code in client callable UI action.
Please Mark this Helpful and Accepted Solution if it solves your issue.
Thanks & Regards,
Shikha Tyagi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:48 PM
Yes, you can indeed have different server-side actions based on the conditions in your client-side script. However, you can't directly call a server-side script from the client-side "else" block. Instead, you would typically use an AJAX call to invoke a specific Script Include or another server-side script.
function confirmUpdate() {
var answer = confirm('This will update all records! Are you sure?');
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'updateConfirm');
} else {
// Trigger other server-side action using AJAX
var ga = new GlideAjax('MyUpdateHandlerScript'); // Replace 'MyUpdateHandlerScript' with the name of your Script Include or server-side script
ga.addParam('sysparm_name', 'otherUpdateAction'); // Define the specific action you want to trigger
ga.getXMLAnswer(function(response) {
// Handle the response here if needed
alert(response); // For example, alert the response from the server-side action
});
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks