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-16-2020 04:17 PM
Does a record actually get created in the sys_attachment table?
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:38 PM
Interestingly one does get added to the sys_attachment table now that I've removed that line from the script, and I can find a newly created record that has the attachment, though the rest of the fields are blank.
In this case it's the custom base table that the others in the script are extended from.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 05:27 PM
So it seems like perhaps that line was there to prevent that empty base record from being created? Unfortunately I believe the fact that you are ending up with a record not in the table to which the record producer is tied is the reason that the attachments are not coming though. The system is trying to target the record that it "thinks" should be created, rather than the one you are actually creating.
Michael D. Jones
Proud member of the GlideFast Consulting Team!