Display info message on list once record is created in the table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am using below Sever script in Related LIST UI Action. whenever click on UI Action record will created if does not exists and if it exists it wont create any anything. My Requirement whenever is created it should show a message in list view Below is my existiing code
// Client-side callback to refresh the related list after server-side execution
function refreshRelatedList() {
g_form.refreshRelatedList('sn_customerservice_contact_relationship'); // Forces a refresh of the related list
}
// Server-side logic (your original code)
(function() {
var contact = current.sys_id;
var account = current.account;
var oldResp = '8c47fe14833d42d46c06c3efeeaad329'; // PM – auto notify
var newResp = '3d6bd2cf2be03614e5f9f646c891bf1c'; // Automated PM Notification
// Try to find the "auto notify" record
var grOld = new GlideRecord('sn_customerservice_contact_relationship');
grOld.addQuery('contact', contact);
grOld.addQuery('company', account);
grOld.addQuery('responsibility', oldResp);
grOld.query();
if (grOld.next()) {
// If PM – auto notify exists, update it to Automated PM Notification
grOld.responsibility = newResp;
if (grOld.update()) {
gs.addInfoMessage(
'Updated PM – auto notify to Automated PM Notification for ' +
contact.getDisplayValue()
);
} else {
gs.addErrorMessage(
'Failed to update to Automated PM Notification for ' +
contact.getDisplayValue()
);
}
} else {
// If no "auto notify" exists at all, create only Automated PM Notification
var grNew = new GlideRecord('sn_customerservice_contact_relationship');
grNew.initialize();
grNew.contact = contact;
grNew.company = account;
grNew.responsibility = newResp;
if (grNew.insert()) {
gs.addInfoMessage(
'Created Automated PM Notification for ' +
contact.getDisplayValue()
);
gs.addInfoMessage('Automated PM has been created');
} else {
gs.addErrorMessage(
'Failed to create Automated PM Notification for ' +
contact.getDisplayValue()
);
}
}
gs.info('UI Action completed for record ' + current.sys_id);
})();
// Call the client-side refresh after server-side execution
refreshRelatedList();
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Mannam Praveen ,
Correct your UI Action as below and try:
- Client: Checked
- OnClick: runClientSide()
- List context: Checked (True) (Assuming this is a List Bottom button or similar)
- The Script:
// --- Client Side Function ---
function runClientSide() {
// We use g_list.getChecked() if this is a list button with checkboxes,
// but for a related list button that acts on the current record, we just submit.
gsftSubmit(null, g_form.getFormElement(), 'action_name_of_your_ui_action');
// IMPORTANT: Replace 'action_name_of_your_ui_action' with the actual "Action name" field value of this UI Action.
}
// --- Server Side Code ---
if (typeof window == 'undefined') {
runServerSide();
}
function runServerSide() {
var contact = current.sys_id;
var account = current.account;
var oldResp = '8c47fe14833d42d46c06c3efeeaad329'; // PM – auto notify
var newResp = '3d6bd2cf2be03614e5f9f646c891bf1c'; // Automated PM Notification
// Define the URL to redirect to (stay on the same page)
// This is the KEY to showing the message. We must reload the page with the message attached.
action.setRedirectURL(current);
// Try to find the "auto notify" record
var grOld = new GlideRecord('sn_customerservice_contact_relationship');
grOld.addQuery('contact', contact);
grOld.addQuery('company', account);
grOld.addQuery('responsibility', oldResp);
grOld.query();
if (grOld.next()) {
// Update logic
grOld.responsibility = newResp;
if (grOld.update()) {
gs.addInfoMessage('Updated PM – auto notify to Automated PM Notification.');
} else {
gs.addErrorMessage('Failed to update record.');
}
} else {
// Insert logic
// Check if the new record ALREADY exists before inserting (Prevent Duplicates)
var grCheck = new GlideRecord('sn_customerservice_contact_relationship');
grCheck.addQuery('contact', contact);
grCheck.addQuery('company', account);
grCheck.addQuery('responsibility', newResp);
grCheck.query();
if (!grCheck.hasNext()) {
var grNew = new GlideRecord('sn_customerservice_contact_relationship');
grNew.initialize();
grNew.contact = contact;
grNew.company = account;
grNew.responsibility = newResp;
if (grNew.insert()) {
// THIS is the message you wanted
gs.addInfoMessage('Automated PM has been created');
} else {
gs.addErrorMessage('Failed to create Automated PM Notification.');
}
} else {
gs.addInfoMessage('Automated PM Notification already exists. No changes made.');
}
}
}
Regards,
Vishal