Fetch data from an external API and display on a field when I click on the UI Action button

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 04:28 PM
Hello everyone, I need some assistance with this. I want to display data on a field when I click on the UI Action button. I have created an Action to fetch data from an external API. can someone help me get this done better.
screenshots:
Here is the UI Action script copied from the Action and modified a bit:
(function() {
try {
var inputs = {};
inputs['date'] = current.getValue('date'); // Date
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().action('x_842414_stock_exc.get_stock_info').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().action('x_842414_stock_exc.get_stock_info').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Get Outputs:
// Note: outputs can only be retrieved when executing synchronously.
var stock_summary = outputs['stock_summary']; // Object
gs.info(stock_summary + 'line 17');
// console.log(stock_summary + 'line 18');
current.setValue('stock_summary', stock_summary);
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
I would appreciate the assistance,
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 01:39 PM - edited 06-22-2023 01:39 PM
Hello @Ifeanyi Kingsle
I do understand the requirement, but this won't work. The code you copied is server code and should not be used from a client UI action. if the purpose is to fetch it from the client, then I would recommend you using a display business rule on the table, call the script and store the result in the scratchpad.
Then the only thing you need in the UI action is a small code that fetches the data from the scratchpad object and populates it into the field.
Hope this helps you any further.