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

Marcel H_
Tera Guru

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);

 

 

7 REPLIES 7

Does a record actually get created in the sys_attachment table?

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

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.

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. 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!