How do I add an attachment to a Record Producer with a switch case script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2020 01:58 PM
I am currently using a formatter configured as a button on a form that redirects to a record producer with a choice field that allows the user to decide what type of record they want to create.
I was attempting to add an attachment button that we have set up in a macro type variable, and is used on other forms in the instance with no issues, but the selected attachment never gets added to the new record in this case. This also occurs with the OOB paperclip icon as well, so I think that something isn't being referenced or called that is necessary to add the attachment correctly.
Below is the script that is used on this record producer:
var newGR = new GlideRecord(producer.record_type + '');
newGR.initialize();
switch(producer.record_type + '') {
case 'u_test_1_records':
newGR.u_person = producer.person;
newGR.u_short_description = producer.person.u_name + ": Test 1";
break;
case 'u_test_2_records':
newGR.u_person = producer.person;
newGR.u_short_description = producer.person.u_name + ": Test 2";
break;
case 'u_test_3_records':
newGR.u_person = producer.person;
newGR.u_short_description = producer.person.u_name + ": Test 3";
break;
}
var newSysID = newGR.insert();
var url = producer.record_type + '.do?sys_id=' + newSysID;
gs.addInfoMessage(newGR.u_number + ' created for ' + producer.person.u_name);
producer.redirect = url;
current.setAbortAction(true);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2020 09:41 PM
What was the need to create attachment icon , when OOB attachment link is already there on record producer.
Have I understood your question wrongly ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 12:00 PM
Thanks for replying to my post.
The core issue is that neither method works with this record producer, including the OOB attachment link. I'm not sure if it's because of the way that this record producer works and the table isn't predefined since we need to let the user choose which table it's created on and the system doesn't know what sys_id to attach to, or if it's something else.
I'm wondering if in the different case script sections if I have to somehow specify that the attachment needs to be added to the new sys_id, in a similar way that the url is calling that to do the redirect at the end of the script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 02:02 PM
Is there a reason you are calling current.setAbortAction(true); at the end of your script?
I believe that is the reason the attachment is not being carried over by the default functionality.
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 04:11 PM
Actually that seems to be a remnant from other testing and forgot to comment that out.
Removing that line doesn't change the behavior however and attachments still do not get added to the newly created record.