Email Notification on click of button can we run any server side?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The email must include an option to extend the variable value for another 15, 30, or 90 days. When Clicking on 15 days, 30 days or 90 Days . Is it possible to call server side code ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @abhishekraman ,
I tried your useCase . For this i created one email notification,flow designer flow and Scripted Rest api and its updating RITM Variable . Also Created one renewal_days variable in catalog item .
Steps :
Created renewal_days variable in the catalog item
Developed a Scripted REST API to update RITM variables
Configured email notification with action links (15 / 30 / 90 days)
Linked email buttons to the Scripted REST API
Created Flow Designer flow attached to the catalog item
Flow triggers on RITM update for post-processing
Tested the complete flow using REST API Explorer
Please Refer this Scripted rest api script :
(function process(request, response) {
// var ritmSysId = request.queryParams.ritm_sys_id;
// var days = parseInt(request.queryParams.days, 10);
var ritmSysId = request.queryParams.ritm_sys_id[0];
var days = parseInt(request.queryParams.days[0], 10);
gs.info('=== Extend Renewal API Called ===');
gs.info('URL: ' + request.url);
gs.info('ritmSysId: ' + ritmSysId);
gs.info('days: ' + days);
// 1. Validate parameters
if (!ritmSysId || !days) {
response.setStatus(400);
response.setBody({
status: "error",
message: "Missing parameters",
received: {
ritm_sys_id: ritmSysId,
days: days
}
});
return;
}
if ([15, 30, 90].indexOf(days) === -1) {
response.setStatus(403);
response.setBody({
status: "error",
message: "Invalid extension value. Allowed values: 15, 30, 90"
});
return;
}
// 2. Fetch RITM
var ritm = new GlideRecord('sc_req_item');
// Log the query
gs.info('Querying sc_req_item with sys_id: ' + ritmSysId);
gs.info('RITM found: ' + ritm.number + ' (sys_id: ' + ritm.sys_id + ')');
// 3. Check if already extended
var currentRenewalDays = ritm.variables.renewal_days;
// if (currentRenewalDays && currentRenewalDays != '') {
if (currentRenewalDays) {
response.setStatus(200);
response.setBody({
status: "info",
message: "Renewal already extended by " + currentRenewalDays + " days",
ritm: ritm.number.toString()
});
return;
}
// 4. Update variable
var data='';
try {
if (ritm.get(ritmSysId)) {
ritm.variables.renewal_days = days;
data=ritm.update();
}
gs.info('Successfully updated RITM ' + ritm.number + ' with renewal_days: ' + days);
} catch (e) {
gs.error('Error updating RITM: ' + e.message);
response.setStatus(500);
response.setBody({
status: "error",
message: "Failed to update RITM: " + e.message
});
return;
}
// 5. Success response
var gd=new GlideRecord('sc_req_item')
if(gd.get(data))
{
var num=gd.number
}
response.setStatus(200);
response.setBody({
status: "success",
message: "Renewal extended by " + days + " days",
ritm: num,
ritm_sys_id: ritm.sys_id
});
})(request, response);
Email Notification Body :
<p>Hello,</p>
<p>
Your request requires a renewal extension.
Please choose one of the options below:
</p>
<p>
<a style="
padding:10px 16px;
background-color:#4CAF50;
color:#ffffff;
text-decoration:none;
border-radius:4px;
display:inline-block;"
href="https://devxxxxx.service-now.com/api/1795019/testingbtn/extend?ritm_sys_id=${sys_id}&days=15">
Extend by 15 Days
</a>
</p>
<p>
<a style="
padding:10px 16px;
background-color:#2196F3;
color:#ffffff;
text-decoration:none;
border-radius:4px;
display:inline-block;"
href="https://devxxxxx.service-now.com/api/1795019/testingbtn/extend?ritm_sys_id=${sys_id}&days=30">
Extend by 30 Days
</a>
</p>
<p>
<a style="
padding:10px 16px;
background-color:#FF9800;
color:#ffffff;
text-decoration:none;
border-radius:4px;
display:inline-block;"
href="https://devxxxxxx.service-now.com/api/1795019/testingbtn/extend?ritm_sys_id=${sys_id}&days=90">
Extend by 90 Days
</a>
</p>
<p>
<b>Note:</b> This action can be performed only once.
</p>
<p>Thank you,<br>
ServiceNow Team</p>
Please refer following Screenshots:
If this helps you then mark it as helpful and accept as solution.
Regards,
Aditya,
Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @abhishekraman ,
Did my response helps you ? If yes then mark it as helpful and accept as solution.
Regards,
Aditya,
technical consultant
