Trigger an email notification using script include and onChange Clientscript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 04:42 AM
Hi all,
i need to trigger an email notification if state contains "US" and stage is in progress emails need to be triggered. I have created a onChange client Script and Script Include.
Type - OnChange
FieldName - State
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue.indexOf('US')) {
var ga = new GlideAjax('TriggerEmailforUSstate');
ga.addParam('sysparm_name', 'myfunction'); //method
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == true){
alert(answer);
}
}
}
}
Script Include:
var TriggerEmailforUSstate = Class.create();
TriggerEmailforUSstate.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
myfunction: function() {
if (current.stage == 'Progress')
gs.eventQueue('event registry', 'current','', '');
return true;
},
type: 'TriggerEmailforUSstate'
});
please help me on this how to write a code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 07:11 AM
@priyanka68 Try using Business rule. Write After update business rule , put your condition and in advance section use gs.eventQueue with all parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 07:23 AM
Current won't be available in that script - you should pass as another parameter the record's stage value:
ga.addParam('sysparm_stage',g_form.getValue('stage_field'));
Then in the script include, you need to get that param:
var currStage = this.getParameter('sysparm_stage');
Then replace the "current.stage" with currStage.
Also, validate that the backend value of the state has US capitalized. If not, you need to change to lowercase because newValue is going to be the backend value. Same for your script include stage - it will get the backend value of the field.