- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2016 01:07 PM
Hi all,
I have a reference field and a UI Macro button that can send an email to the person in the field.
I would like the UI Macro work only if all mandatory fields were populated, and if not they are not filled, to pop up an alert and abort.
If all mandatory fields are populated, clicking on the UI Macro button saves the form and pops up the email.
This is what I am currently using (based on Mike Allen's answer to this post.)
function sendMail() {
var case1 = g_form.getValue('u_alternative_approver');
if(case1 == '') {
alert('Please complete all mandatory fields and save the form before sending a mail.');
return false;
}
g_form.save();
var sys_id = g_form.getUniqueValue();
var url = "email_client.do?sysparm_table=u_new_employee_requests&sysparm_sys_id=" + g_form.getUniqueValue() + "&sysparm_target=u_new_employee_requests&sys_target=u_new_employee_requests&sys_uniqueValue=" +g_form.getUniqueValue() + "&sys_row=0&sysparm_encoded_record=&u_new_employee_requests.u_email_type=e48c5d9537fce600865bdb9643990e9b&sysparm_domain_restore=false&sysparm_stack=no";
window.open(url, '_blank');
window.focus();
}
The problem with the script is that it only checks if the field alternate approver is empty. If it is not empty, a regular pop up "The following mandatory fields are not filled in:..." will appear and then proceed to show the email anyway. However, the email must contain data from mandatory fields, and if the data is not there, the email is empty.
So I need to abort if mandatory fields are not populated.
How do I do that?
Thanks
harel
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2016 05:52 PM
Instead, I put in a client script that hides the button if it's a new record. This way, all mandatory fields will have to be filled anyway before submitting the form, and then the UI Macro will show.
function onLoad() {
//Type appropriate comment here, and begin script below
var el = document.getElementById('mailbtn');
if(g_form.isNewRecord()){
el.style.display = 'none';
} else {
el.style.display = 'inline';
}
}
I can also cut my UI Action to this:
function sendMail() {
var sys_id = g_form.getUniqueValue();
var url = "email_client.do?sysparm_table=u_new_employee_requests&sysparm_sys_id=" + g_form.getUniqueValue() + "&sysparm_target=u_new_employee_requests&sys_target=u_new_employee_requests&sys_uniqueValue=" +g_form.getUniqueValue() + "&sys_row=0&sysparm_encoded_record=&u_new_employee_requests.u_email_type=e48c5d9537fce600865bdb9643990e9b&sysparm_domain_restore=false&sysparm_stack=no";
window.open(url, '_blank');
}
What do you think?
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 12:19 AM
HI Abhinay,
When I click on the UI Macro button, I get back to the list of records, and no email shows...
By the way, any idea why this shows an error "el is null":
function onLoad() {
//Type appropriate comment here, and begin script below
var el = document.getElementById('mailbtn');
if(g_form.isNewRecord()){
el.style.display = 'none';
} else {
el.style.display = 'inline';
}
}
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 06:31 AM
Yes, well, the client script did not work because I had an extra space in the ref_contributions statement:
ref_contributions<space>=email_alternative_manager
instead of
ref_contributions=email_alternative_manager

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:26 AM
Did you get this working? or you still looking for help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:34 AM
Hi Abhinay,
I got it to work using the client script. It is not exactly what I had in mind at the beginning, but it does the job.
Thanks.
Harel

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 08:36 AM
Glad, you got it working. Please mark your answer as correct and close this thread. let me know if you nay questions.