- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 07:51 AM
Hi All,
I have a requirement, I need to check whether the variable value has changed in the RITM process and send the notification to the requested_for as the variable value you entered is updated.
Can you guys please help me on this.
Thanks
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2018 08:49 AM
Hi All,
Thanks for your reply,
I have created on submit client script and script include for checking the old and new values of the variable on the (RITM) and sending notification if it is changed. The below one is working.
Client script, on submit():
var el_id = g_sc_form.getControl("u_impact_assessment").id;
//u_impact_assessment it is the variable name
var orig_val = gel("sys_original."+ el_id).value;
var new_val = g_form.getValue("u_impact_assessment");
if(orig_val != new_val){
var ga = new GlideAjax('ModelCategoryDet');
ga.addParam('sysparm_name','sendNotification');
ga.addParam('sysparm_sys_id',g_form.getUniqueValue());
ga.getXML();
}
Script include:
sendNotification: function() {
var Sys_id = this.getParameter('sysparm_sys_id');
var gr = new GlideRecord("sc_req_item");
gr.get(Sys_id);
gs.eventQueue('XXXX',gr,'','');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 10:37 PM
Hi San 1989, the same issue have facing now can provide some help on this.Check the below content
Im working with email notifications on ritm table. I have 7 catalog items on my order guide. if i submit record on any these catalog items it will generated ritm. In that ritm if i modified one or more variables and hit the save button notification should be sent for group(YY) of that ritm and assigned to person.
As of now it is working correctly for modification one variable,if i modified more than one variable notification is triggering each variable modified.How to get all the modified variables in one notification
Please help me on this on provide the sample code with example.
Below are the scripts im using for notification
Email Script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
email.setSubject(current.number +' Variables have been modified');
template.print('This notification is to alert you that one or more Variables have been modified on '+current.number+"<br/>\n\n");
var value = event.parm1.split(',');
template.print(event.parm2+': '+value[1]+' = '+event.parm2+': '+value[0]+' was modified by '+current.sys_updated_by+' at '+current.sys_updated_on);
})(current, template, email, email_action, event);
Business rule on sc_item_option table.
Condition: javascript:new GetitemForVariable().getItem(current.sys_id)
(function executeRule(current, previous /*null when async*/) {
//get current and previous value of the variable concatenated with ","
//and the question name(name of the variable)
var prepost = current.value+','+previous.value;
var question = current.item_option_new.getDisplayValue();
//get the sys_id of the ritm connected to this variable
var item = new GetitemForVariable().getreqitem(current.sys_id);
//get glideobject of the requested item to be used to pass in the event
var gr = new GlideRecord('sc_req_item');
gr.get(item);
gr.query();
if(gr.next()){
gs.eventQueue('Ritm.Changes.Variables',gr,prepost,question);
}
})(current, previous);
Script include:
var GetitemForVariable = Class.create();
GetitemForVariable.prototype = {
initialize: function() {
},
//check if the catalog item of the variable is equal to the particular catalog item's sys_id or not
getItem: function(sys_id){
var gr = new GlideRecord('sc_item_option_mtom');
gr.addEncodedQuery('sc_item_option.sys_idSTARTSWITH'+sys_id);
gr.query();
if(gr.next()){
//return gr.request_item.cat_item.toString() == 'ae244264dbb6c700c77b7016bf961944';//sys_id of your catalog item
var item = gr.request_item.cat_item.toString();
if(item == 'e7d48d55db5f8b00c77b7016bf96199b' || item == 'e386bfb3dba68700c77b7016bf961943' || item =='ae244264dbb6c700c77b7016bf961944' || item =='1813429bdb83c700f3e5f156bf9619e9' || item =='0d0c3f5adb28e3001ac0105f6896198e' || item =='f2377d15db9f8b00c77b7016bf96191c' || item =='f477b155db9f8b00c77b7016bf961967'){
return true;
}
}
},
getreqitem:function(sys_id){
var gr = new GlideRecord('sc_item_option_mtom');
gr.addEncodedQuery('sc_item_option.sys_idSTARTSWITH'+sys_id);
gr.query();
if(gr.next()){
return gr.request_item;
}
},
type: 'GetitemForVariable'
};
Please check this and provide some solution.
If any new way to get the solution for above requirement please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 09:26 AM
Hi,
Try to create onSubmit() client script on all the RITMS(catalog items) and you can use my script above one. I have used only for the one variable, but you can check for all the variables you have.
Client script, on submit():
var el_id = g_sc_form.getControl("u_impact_assessment").id;
//u_impact_assessment it is the variable name
var orig_val = gel("sys_original."+ el_id).value;
var new_val = g_form.getValue("u_impact_assessment");
var variable_1 = g_sc_form.getControl("variable_1").id;
var variable_2 = g_sc_form.getControl("variable_2").id;
var variable_3 = g_sc_form.getControl("variable_2").id;
.
.
.
var variable_n = g_sc_form.getControl("variable_n").id;
var orig_val_1 = gel("sys_original."+ variable_1 ).value;
var new_val_1 = g_form.getValue("variable_1 ");
... up to n
if((orig_val != new_val) || (orig_val_1 != new_val_1) ||...){
}
use my same script include and try..
because in this case, what ever the variables user changes, notification only triggers when the form is submitted.
Try this, let me know if you face any difficulty.
Thanks