What's the best way to display a soft alert box th...
# ask-stanley-ai
a
What's the best way to display a soft alert box through user event script when a user tries to save the record but the condition is not met?
c
AI generated answer (using internal Slack threads):
The best way to display a soft alert box through a user event script when a user tries to save the record but the condition is not met is to use a combination of User Event and Client scripts. In your User Event script, you can include a Client Script in the
beforeLoad()
function. Here is a sample code snippet:
Copy code
javascript
if(runtime.executionContext == runtime.ContextType.USER_INTERFACE)
    context.form.clientScriptModulePath = ‘path/to/your/client/script’;
Then, in your Client Script, you can adjust the content of an HTML field to display the warning message. You can make the default value of the inlineHTML something like
<div id="fill_this_in_on_page_load"></div>
, and then your client script would have something like
jQuery('#fill_this_in_on_page_load').html('here is my fancy HTML');
. Alternatively, you can use the
N/ui/message
module to display your message as a banner. Here is a sample code snippet:
Copy code
javascript
var message = message.create({
    type: message.Type.WARNING,
    title: "Warning",
    message: "Your warning message here"
});
message.show();
Remember to return
false
in the
saveRecord
function of your Client Script if the condition is not met. This will prevent the record from being saved. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839948416
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839697778
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838819265
Please provide your feedback on this answer.