- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2018 01:39 PM
We have some users who interact with SerivceNow via a separate web portal. Management from the other portal has requested that the notifications for companies that use the other web portal use a URL for that portal. So we have a check box on the companies that use the other web portal.
The ask is that for notifications if the "u_in_portal" is true the URL look something like https://portal.com/ticket_type/[sys_id]
the if "u_in_portal" is false use the regular ServiceNow URL to the record
Is there a way to dynamically add the URL to the email notification based on the "u_in_portal" filed on the company page?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2018 06:47 AM
Final solution
var num = current.sys_id; //quick easy grab of current record sys_id to use in building URL
var gr = new GlideRecord('change_request'); //New glideRecord on change_request table
gr.addQuery("sys_id", num); //Limits the record look up to just the current record sys_id
gr.query(); //executes the query
while (gr.next()); //while there is a next record (esentially for each record found) do the following
//If the check box is true (checked)
if (gr.u_checkbox == true){
//Start of string sentence to show in the email body
template.print("More details can be found ");
//create variable to incld the part of the URL that will remain constant + the current sys_id variable from above (num)
var pLink = "https://company.com/subsite/support/#/editChangeRequest/" + current.sys_id;
//create html anchor (<a href) to create the actual URL link using the word here as the text link
var pAnchor = "<a href='" + pLink +"'>" + "here." + "</a>";
template.print(pAnchor + "<br />");
}
//If the \check box ix false (not checked) then the URL link will be created the same way as above, but will link back to the record in ServiceNow
if (gr.u_checkbox == false){
template.print("More details can be found ");
var sLink = "https://instance.service-now.com/nav_to.do?uri=change_request.do?sys_id=" + current.sys_id;
var sAnchor = "<a href='" + sLink +"'>" + "here." + "</a>";
template.print(sAnchor + "<br />");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2018 01:53 PM
Hi tkh,
You an do that with notification email scripts. See the documentation here:
In the script, you can query your company table, build and print a URL appropriate to the situation, based on the caller in the record for example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 12:14 PM
So I have a true/false field on the company table called u_inPortal.
This field has been added to the Change form as a reference field.
inside an email notification script, I need to check the u_inPortal field of the current change record to see if it is true or false.
If True the email script will create one URL, if false it will create a different URL.
I have all the parts working except for the getting the true or false value of the u_inportal field it either always comes back false or as undefined.
Here is my script.
var num = current.sys_id;
dothis();
function dothis(){
var answer = current.company.u_inportal;
template.print("In Portal is "+ answer + "<br />"); //for testing
if (answer == true){
template.print("More portal details ");
var pLink = "https://console.test.cloud.ibm.com/managed-solutions/support/#/editChangeRequest/" + current.sys_id;
var pAnchor = "<a href='" + pLink +"'>" + "here" + "</a>";
template.print(pAnchor + "<br />");
}
if (answer == false){
template.print("More ServiceNow details ");
var sLink = "https://ibmmhasdev2.service-now.com/nav_to.do?uri=change_request.do?sys_id=" + current.sys_id;
var sAnchor = "<a href='" + sLink +"'>" + "here" + "</a>";
template.print(sAnchor + "<br />");
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 12:27 PM
Does it come back as true if you check the box on one of the companies in a non-production environment? Usually on a true/false, I'll code for the true case - so:
if (answer == true) {
// Do something
} else {
// Do something else
}
That way I'll at least get the else case. (I feel like sometimes it will come back as undefined if the box has never been checked, but don't quote me on that.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 01:42 PM
no matter whether the box is checked or not it comes back false.
maybe do a if not null then do this else do that. 🙂