- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2025 08:26 AM - edited ‎03-29-2025 08:37 AM
Hi All,
The requirement is when a Request is closed and the email is sent, we need to provide an option(button) in the email to the requestor to create an incident from the esc portal via a custom record producer, link the request in the incident(pre-fill details of request in record producer variables ), then requestor can edit/add details and submit the record producer.
Pre filled details on record producer form-
1. Variable - 'Requested for' should be pre-filled with the 'Requested for' of the Request.
2. Variable - 'Summarize your incident' should be pre-filled with 'Request number and RITM short description'
Backend name of the variables- Requested For(name - requested_for) and Summarize your incident(name - issue)
I designed a solution below-
Created an email script and called that inside the notification.
Now, the issue I am facing is-
The button is redirecting to a record producer form on esc portal but variables are not getting pre-filled.
I have used below email script-
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var callerSysId = "";
var shortDesc = "";
// Get the Requested For (Caller ID) from RITM
if (current.requested_for) {
var caller = new GlideRecord('sys_user');
if (caller.get(current.requested_for)) {
callerSysId = caller.sys_id;
}
}
// Get the Request Number from the Parent Request
var reqNumber = "";
if (current.request) {
var requestRecord = new GlideRecord("sc_request");
if (requestRecord.get(current.request)) {
reqNumber = requestRecord.number;
}
}
// Get RITM Details
var ritmShortDesc = current.short_description || "";
// Construct Prefill Values
shortDesc = reqNumber + " - " + ritmShortDesc;
// Encode Only Text Fields
callerSysId = encodeURIComponent(callerSysId);
shortDesc = encodeURIComponent(shortDesc);
// Get the instance name dynamically
var instanceName = gs.getProperty('instance_name');
var instanceUrl = 'https://' + instanceName + '.service-now.com/';
// Incident Record Producer sys_id (Replace with your actual Record Producer sys_id)
var recordProducerSysId = "41157e8bdbe70510491b5fc4e2961951";
// Construct the Record Producer URL with prefilled variables
/* var recordProducerUrl = instanceUrl + 'esc?id=sc_cat_item&sys_id=' + recordProducerSysId +
'&variables.requested_for=' + requestedForSysId + // Requested For
'&sysparm_variables=issue=' + summary;*/
//'&variables.issue=' + summary; // "Summarize Your Incident"
var recordProducerUrl = instanceUrl + 'esc?id=sc_cat_item' +
'&sys_id=' + recordProducerSysId +
'&sysparm_direct=true' +
'&sysparm_query=requested_for=' + callerSysId +
'^issue=' + shortDesc;
// Generate the Button in the Email
template.print(new global.OutlookRoundedButton().getDynamicSizeButtonHTML(
'Create an Incident',
'16',
'FFFFFF',
'059BD2',
'7',
'20%',
recordProducerUrl
));
I tried building different url in the email script but no luck-
1. var recordProducerUrl = instanceUrl + 'esc?id=sc_cat_item' +
'&sys_id=' + recordProducerSysId +
'&sysparm_direct=true' +
'&sysparm_query=requested_for=' + requestedForSysId +
'^issue=' + summary;
2. var recordProducerUrl = instanceUrl + 'esc?id=sc_cat_item&sys_id=' + recordProducerSysId +
'&variables.requested_for=' + requestedForSysId + // Requested For
'&variables.issue=' + summary; // "Summarize Your Incident"
3. var recordProducerUrl = instanceUrl + 'esc?id=sc_cat_item' +
'&sys_id=' + recordProducerSysId +
'&sysparm_direct=true' +
'&sysparm_variables.requested_for=' + requestedForSysId +
'&sysparm_variables.issue=' + summary;
When I hover on the button, I can see the link with correct values passed in the URL parameters but they are not getting filled when the record producer form opens on click of the button.
Can someone please help me resolve the issue?
Any help is highly appreciated.
@Ankur Bawiskar @Pradeep Sharma @Mike Patel
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2025 07:35 PM
Your URL from email script should be like this
var recordProducerUrl = instanceUrl + 'esc?id=sc_cat_item' +
'&sys_id=' + recordProducerSysId +
'&sysparm_direct=true' +
'&requestedFor=' + requestedForSysId +
'^issue=' + summary;
have you written onLoad catalog client script to get the values from URL and then set it?
try this
var url = top.location.href;
var requestedFor = new URLSearchParams(url).get("requestedFor");
var issue = new URLSearchParams(url).get("issue");
// then set the value to your variable using g_form.setValue('variableName', issue);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 04:40 AM
Glad to know.
Please mark my response as correct and close the thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 08:02 PM
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader