How do I validate attachment name on record producer before submission?

HowTo

I have a record producer that creates a record on a custom table.

I need users to be able to add attachments but the attachment name needs to be written in a specific way depending on what they select on the form.

Example format: variable1_variable2.jpg

I can find lots of guides on how to make attachments mandatory but how do I validate an attachments name before submission? If the attachment name isn't in the right format need to remove it from the page also.

Posted Mar 20, 2023, 9:48 PM UTC

26
Murdeus•

As previous comment said, you need to set up a script (probably onSubmit ajax) to query the sys_attachment table and check file name. Table name and ID to query on actually depends on the version of sc_cat_item widget you’re using. Run some tests to check those, and from there you should be fine as long as you understand how to get the table sys_id of the record before creation

2
RaynorUE•

You'll need to do a client script with some glideajax as noted in other comments.

The only key thing to know about a record producer, is in client side, g_form.getUniqueValue() should be the sys_is the record WILL be.... I think .. it might also be the sys_id of the users sc_cart record, which is where the attachment will go somewhere in there...

2
Realistic-Ad-4372•

Try query the sys_attachment, a record should be created in that table after you attach the file, even if not submitted. Also check for "excel record producer" on community, maybe GlideSysAttach has some nice method to solve your problem.

1
MebaccaOP•

Ok, wasn't sure I'd be able to do that pre submission will take a look.

1
AutomaticGarlic•

Why not just query the attachment and set the name to what it needs to be, versus validation and putting this on the user?

1
MebaccaOP•

Could be an option but I think the person who has asked for this would want the user to double check they attached the right thing in this case as it could cause some issues if the wrong item is attached as the person who action's it wouldn't know if its correct or not.

1