- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 03:02 AM
Hi Everyone,
I have created UI macro and notification in my instance. And I want to call notification in UI Macro.
My UI macro , creates a button on form and when it is clicked then a table pops up and I select a record from table. The details of selected records get populated in additional comments.
So, my task is to send notification when I a record is selected. So , I am planning to call notification through UI Macro when record is selected.
UI Macro:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>
function macroLoading(){
const btn = document.createElement("button");
btn.innerHTML = "CareAR Instruct";
btn.id = "customButton";
btn.type="button";
document.getElementById("element.sn_customerservice_case.watch_list").appendChild(btn);
document.getElementById("customButton").addEventListener("click", myFunction);
//return false;
}
function myFunction(){
var table = 'x_care3_carear_fsm_instruct_experience';
var tableList = 'x_care3_carear_fsm_instruct_experience_list';
var dialog = new GlideDialogForm('Instruct Experience' ,tableList);
dialog.setTitle(table + " List");
dialog.setLoadCallback(populateCaseComments);
dialog.render();
function populateCaseComments(item) {
var fields = ["instruct_model_name", "instruct_model_url", "model_description"];
var msg = "";
fields.forEach(function(field) {
msg += item.getElementById(table + "." + field).value + "\n";
});
g_form.setValue("comments", msg);
if (item.getElementById('sys_uniqueValue').value)
dialog.destroy();
}
}
window.onload = macroLoading;
</script>
</j:jelly>
Thanks and regards
cc: @Ankur Bawiskar @kamlesh kjmar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:38 AM
Hi @Abhijit Das7 ,
To call a notification from UI Macro on select of any record, follow the below steps :
1. Create an Event record in Event registry module
2. Create a notification in Notifications module and trigger when event (event that you created in step1) is fired:
3. Make sure you define a valid recipient in Who will receive section. For this example I have kept it system administrator, you can make it dynamic by passing recepient from the event parm1/parm2
4. Create a script include to call an event. It should be client callable so that you can call it from UI Macro, below a sample script.
var notify = Class.create();
notify.prototype = Object.extendsObject(AbstractAjaxProcessor, {
notifyEndUser : function(){
var record = this.getParameter("record"); //sys_id of the record against which event is triggerd, passing this from UI Macro
var table = this.getParameter("table"); // Table name against whose record event will be triggered, passing this from UI Macro
var getRecord = new GlideRecord(table);
getRecord.get(record);
gs.eventQueue("notify.user", getRecord, "", ""); //Triggering the event, you can pass the dynamic recepient in second last or last parameter
},
type: 'notify'
});
5. Open your UI Macro and call this script include to trigger the event which will eventually trigger your notification:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>
function macroLoading(){
const btn = document.createElement("button");
btn.innerHTML = "CareAR Instruct";
btn.id = "customButton";
btn.type="button";
document.getElementById("element.sn_customerservice_case.watch_list").appendChild(btn);
document.getElementById("customButton").addEventListener("click", myFunction);
//return false;
}
function myFunction(){
var table = 'x_care3_carear_fsm_instruct_experience';
var tableList = 'x_care3_carear_fsm_instruct_experience_list';
var dialog = new GlideDialogForm('Instruct Experience' ,tableList);
dialog.setTitle(table + " List");
dialog.setLoadCallback(populateCaseComments);
dialog.render();
function populateCaseComments(item) {
var fields = ["instruct_model_name", "instruct_model_url", "model_description"];
var msg = "";
fields.forEach(function(field) {
msg += item.getElementById(table + "." + field).value + "\n";
});
g_form.setValue("comments", msg);
if (item.getElementById('sys_uniqueValue').value){
dialog.destroy();
var eventTrigger = new GlideAjax("notify");
eventTrigger.addParam("sysparm_name","notifyEndUser");
eventTrigger.addParam("table",table);
eventTrigger.addParam("record",item.getElementById('sys_uniqueValue').value);
eventTrigger.getXML(callEvent)
function callEvent(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("Event triggered chech your notification log ");
}
}
}
}
window.onload = macroLoading;
</script>
</j:jelly>
You can check the event log to validate if your event triggered:
Check emails log to validate, if notification triggered
Please let me know if this do not works.
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 11:47 PM
Could you please send the screen shot of whom to send section of your notification. Also could you please confirm, once your event is triggered can you see your event name on Event log