- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 03:57 AM
When using the variable "Attachment" the attachment is not included in the form.
In history I see its included:
But on the form (backend) I dont see an attachment:
On the front (ticket form), I see the attachment in the conversation:
But on the same screen the attachment is empty:
Anyone can help me out?
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 08:30 AM
Sorry, I adapted this from another table and had a typo. In any event, testing this specific scenario I have found that it seems to work better, which means actually work in this case, if the Business Rule is async instead of after. You'll also want to create the BR in the Global scope since you're updating a global table.
Here's the working script, using a better way to specify the table name, which will make it easier to apply the same to other tables.
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'ZZ_YY' + current.getTableName());
attach.addQuery('table_sys_id', current.sys_id);
attach.query();
if(attach.next()){
attach.table_name = current.getTableName();
attach.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 04:45 AM
Hi Mike,
Using the Attachment type variable adds the attachment to the activity stream instead of within the attachment area of the record, which it sounds like is what you are seeing here. You can alter this behavior with a Business Rule, but first you need to confirm the table the attachments are getting added to in your case. The easiest way to do this is to submit a record with an attachment so that you know an attachment record was just created, then look at a list view of the sys_attachment table, sorted descending by Created. The table_name is probably ZZ_YYsn_customer_service_case, but just need to confirm this. Now create an after Insert Business Rule on this table without the ZZ_YY prefix. The BR script is just going to remove that prefix so the attachment shows up where it should.
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'ZZ_YYsn_customerservice_case');//replace with your table name
attach.addQuery('table_sys_id', current.sys_id);
attach.query();
while(attach.next()){
attach.table_name = 'sc_customerservice_case';//replace with your table name
attach.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 06:18 AM
Hi Brad,
Thanks for your fast reply. I just verified and the table is named ZZ_YYsn_customer_service_case.
I'm trying to setup a proper Business Rule. I'm clearly doing something wrong, because it doesn't work the way that I configured it.
When to run:
Actions:
Advanced:
If I like look under tables, I don't see a table named: sc_customerservice_case. I tried renaming it in the script to sn_customerservice_case. This doesn't matter.
Can you help me configure this rule?
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 07:53 AM
Hi Brad,
Thanks for your fast reply. I just verified and the table is named ZZ_YYsn_customer_service_case.
I'm trying to setup a proper Business Rule. I'm clearly doing something wrong, because it doesn't work the way that I configured it.
When to run:
Actions:
Advanced:
If I like look under tables, I don't see a table named: sc_customerservice_case. I tried renaming it in the script to sn_customerservice_case. This doesn't matter.
Can you help me configure this rule?
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 08:30 AM
Sorry, I adapted this from another table and had a typo. In any event, testing this specific scenario I have found that it seems to work better, which means actually work in this case, if the Business Rule is async instead of after. You'll also want to create the BR in the Global scope since you're updating a global table.
Here's the working script, using a better way to specify the table name, which will make it easier to apply the same to other tables.
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'ZZ_YY' + current.getTableName());
attach.addQuery('table_sys_id', current.sys_id);
attach.query();
if(attach.next()){
attach.table_name = current.getTableName();
attach.update();
}
})(current, previous);