
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2019 12:19 PM
Hey SN Comm,
I have a couple of things that I want to see if they can be enhanced. For my first one, we have a UI Action that grabs the attachments from the HR Case, and posts them to the HR Task: (this is in production)
GlideSysAttachment.copy(current.parent.sys_class_name, current.parent, current.getTableName(), current.sys_id);
current.update();
action.setRedirectURL(current);
gs.addInfoMessage("Attachments have been added!");
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
Then, I have a Business Rule to do the following (which is NOT in production yet): This BR automatically allows the case worker, to have the attachments added to the email (from email client) from the Case/Task (depending on which table I give as the target).
(function executeRule(current, previous /*null when async*/) {
//gs.log('M in loop');
// Add your code here
var lookatt=new GlideRecord('sys_attachment');
lookatt.addQuery('table_sys_id',current.instance);
lookatt.query();
while(lookatt.next())
{
// gs.log('M in loop again');
GlideSysAttachment.copy('sn_hr_core_case_operations', current.instance, 'sys_email', current.sys_id);
}
})(current, previous);
I really want to see if there is a way, at least for the UI Action,'Grab Attachments', to make my options selectable. I think it would be really beneficial to be able to do that with these features.
Anyone able to see/or know if this is possible at all?
Thanks in advance!
-Rob
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2019 06:19 AM
Hi Rob,
Yeah I was able to replicate the issue in my Personal Development instance as well. Took me a while and have updated the Business Rule. Just update your Business Rule as per the script mentioned below.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var tic_num = '';
var sub = current.subject;
var number = sub.replace(/[^\d.]/g,'');//current.subject.toString().substr(0,10);
var num = number.substr(0,7);
var num2 =sub.indexOf(num);
if(num2 > 3)
tic_num = sub.substr(num2-3,num.length + 3);
else
tic_num = sub.substr(0,num.length + num2);
var ticket_number = tic_num.replace(/\s/g,'');
// The first 14 characters of the subject are the ticket number.
// We need to subtract this number to get the sys_id of the task record.
var gr = new GlideRecord('incident'); //Replace with your Table Name from which you want to copy to Email Client
gr.addQuery('number',ticket_number);
gr.query();
gr.next();
var arrayAttachment = GlideSysAttachment.copy(gr.sys_class_name, gr.sys_id ,'sys_email', current.sys_id);
for (var i = 0; i< arrayAttachment.size(); i++) {
var attachmentSidsPiece = String(arrayAttachment.get(i)).split(',');
var sourceAttachmentSysid = attachmentSidsPiece[0];
var targetAttachmentSysid = attachmentSidsPiece[1];
var sourceRec = new GlideRecord('sys_attachment');
var targetRec = new GlideRecord('sys_attachment');
if (sourceRec.get('sys_id',sourceAttachmentSysid) &&
targetRec.get('sys_id',targetAttachmentSysid)) {
if (sourceRec.u_send_to_email_client==false) {
//delete all other attachments that are not marked to send via the email client
targetRec.deleteRecord();
} else { //reset the flag
sourceRec.u_send_to_email_client= false;
//as soon as the email record is created, reset the flag to false again
sourceRec.update();
}
}
}
})(current, previous);
Rest of the code remains the same. Hopefully this time it should work:)
Please let me know if still there is an issue and we can check further.
Hope this help. Please mark the answer as helpful/correct based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2019 05:28 AM
So I was able to produce the same results as you. I noticed from your screen shot for your results, that you have two attachments added to that incident, and when your dialog box appears, you only have one option to select.
I too am seeing that issue. I added 5 attachments to my case
clicked on the ui action and got:
And when I check the only box available, I get:
Any reason you could think of, as to why this would happen this way?
Thank you!
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2019 04:39 AM
Hi Rob,
Yes I figured it out why it was not displaying all the attachments in the pop up once the button is clicked irrespective of attachments being present in the original record.
Issue is with the UI Page where I am fetching the attachments. I have Updated the UI Page. Please find the script below
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_sysid" value="${sysparm_sys_id}"/>
<g:evaluate var="jvar_att" jelly="true" object="true">
var arr = [];
var records = [];
var att = new GlideRecord("sys_attachment");
att.addEncodedQuery("table_sys_id=" + jelly.jvar_sysid);
att.orderBy("file_name");
att.query();
while(att.next())
{
arr.push(att.file_name.toString());
records.push(att.sys_id.toString());
}
var arr1 = '';
var records1 = '';
for(var i=0;i<arr.length;i++)
{
if(i == 0)
records1 = records[i];
else if(arr[i] != arr[i-1])
{
records1 = records1 + ',' + records[i];
}
}
var att1 = new GlideRecord("sys_attachment");
att1.addEncodedQuery("sys_idIN" + records1);
att1.query();
att1;
</g:evaluate>
<j2:if test="${jvar_att.hasNext()}">
<j:while test="${jvar_att.next()}">
<g:ui_checkbox name='related_attachment:${jvar_att.getValue("sys_id")}' value='${jvar_att.getValue("file_name")}' class='attachment_checkbox'>${jvar_att.getValue("file_name")}</g:ui_checkbox><br/>
</j:while>
</j2:if>
<br/>
<button onclick="myFunctionSubmit()">Ok</button>
<button onclick="myFunctionCancel()">Cancel</button>
</j:jelly>
Everything remains unchanged just you need to update the HTML portion of the UI Page as per the code I have mentioned above and also have highlighted the line were the issue was checking only for one record and not for all the records.
Only change is addition of code in line number 25 which is mentioned below:
records1 = records1 + ',' + records[i];
I have tested this in my personal instance and it works absolutely fine.
Hope this help. Please mark the answer as helpful/correct based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2019 06:14 PM
Thanks for the help/update with the UI Page. While this works check boxes for each attachment - even if I select only one, all 5 attachments are copied to the email still.
Something else is still copying all attachments, even though I am selecting only one.
Going to try and see why - please let me know if you have any other ideas as to why all attachments are being copied over, regardless of the number of checkboxes I am selecting.
Thank you so much!
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2019 06:27 PM
I feel like it's the BR doing something for some reason. When I click on the normal OOTB E-Mail client icon, all attachments are being copied without me using the UI Action. So the BR is doing it's own thing, in addition as well - when I use the UI Action.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2019 07:12 PM
Did you create the flag u_send_to_email_client in attachment table? Observe this field in sys_attachment, if it setting to true when you select an attachment via UI page and open the email client?
Please mark this response as correct or helpful if it assisted you with your question.