- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 09:41 AM
Hey Community,
I've been working on a widget to create UI action buttons on the Service Portal view of knowledge articles. One of the buttons is to email a knowledge article. I want to have the article's Short Description fill the Subject line and the article's Text along with a link to the article to fill the Body of the email. The link is populating in the email properly. I'm trying to pull the needed data using a GlideRecord, but every time the email opens it just pre-fills as "undefined". I can't figure out if my Server Script or Client Script is incorrect, or both. Any assistance would be appreciated!
Server Script:
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
//looking for input from user on button clicks
if (input && input.action) {
var action = input.action;
// no table associated with this page
if (action == 'email') {
var knowledge = new GlideRecord('kb_knowledge');
knowledge.addQuery('sys_id', data.sys_id);
knowledge.query(); // Issue the query to the database to get relevant records
while (knowledge.next()) {
var subjectKB = knowledge.getDisplayValue('short_description');
var textKB = knowledge.getDisplayValue('text');
data.subject = subjectKB;
data.text = textKB;
}
}
}
})();
data.buttonMsg = gs.getMessage(options.button_text || "Request help");
Client Script:
function($scope) {
var c = this;
c.uiAction = function(action) {
if(action == 'print'){
var printContents = document.getElementById(divName).innerHTML;
w=window.open();
w.document.write(printContents);
w.print();
w.close();
}
else if(action == 'email'){
var emailPrompt = prompt('Please enter a recipient email address', "example@example.com"); //Prompting user to enter address
if(!emailPrompt){ //If blank or cancel - do nothing
return;
}
else{ //if address entered
var email = emailPrompt; //User input of email address
var subject = $scope.data.subject; //Short Description of article
var emailBody = escape(window.location.href + "\n"); //Link to the article
var body = $scope.data.text; //Body of the article
window.location.href = "mailto:"+email+"?subject="+subject+"&body="+emailBody+body; //Opens default email with above info
//filled into the details
}
}
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 12:50 PM
Thank you, this helped. I had to make the following adjustments on the server script to make it work since my Service Portal didn't register the knowledge base table.
(function() {
// Get table & sys_id
data.table = "kb_knowledge";
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
data.subject = gr.getValue('short_description');
data.text = gr.getValue('text');
Unfortunately, when the text is pulled over into the email it shows all the coding for the paragraphs and font adjustments. Much like the following: <p><span style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"><strong><em>
Any ideas on how to show the actual displayed text in it's proper format? gr.getValue and gr.getDisplayValue do the same thing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 09:50 AM
Can you change your server script to
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
data.subject = ge.getValue('short_description');
data.text =ge.getValue('text');
})();
data.buttonMsg = gs.getMessage(options.button_text || "Request help");
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 12:50 PM
Thank you, this helped. I had to make the following adjustments on the server script to make it work since my Service Portal didn't register the knowledge base table.
(function() {
// Get table & sys_id
data.table = "kb_knowledge";
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
data.subject = gr.getValue('short_description');
data.text = gr.getValue('text');
Unfortunately, when the text is pulled over into the email it shows all the coding for the paragraphs and font adjustments. Much like the following: <p><span style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"><strong><em>
Any ideas on how to show the actual displayed text in it's proper format? gr.getValue and gr.getDisplayValue do the same thing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 01:33 PM
You can't build HTML body using mailto:
Check below links
https://stackoverflow.com/questions/5620324/mailto-link-with-html-body
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 07:38 PM
Can you post HTML code for sharing button