- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 01:51 PM
Greetings!
I have a use case where we need to update the parent case of a lifecycle event with a record producer. To prevent creating a new record, I have started the RP script with current.setAbortAction(true) The record producer requires some attachments (number of attachments varies), but since I do not create a record, I do not get the benefit of the attachments automatically associating themselves to a record when they are added.
Based on previous research on the community, I need to populate the 'table_sys_id' and 'table_name' of the sys_attachment record. My understanding is that table_sys_id is supposed to the the sys_id of the record to which I am trying to associate the attachment. But when I look at those sys_attachment records after doing test submissions using the same parent case record, the attachment records have a different table_sys_id from the previous test. All attachments submitted at the same time have the same table_sys_id, but each subsequent test submission has a different table_sys_id.
So my question is, how do I determine the table_sys_id of an attachment which is not associated to a generated record when the record producer is submitted? Or how do I determine the sys_id of the attachments? I think I could make it work from there at least.
Thanks,
S
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 02:56 PM
Hey
To answer your questions: "So my question is, how do I determine the table_sys_id of an attachment which is not associated to a generated record when the record producer is submitted? Or how do I determine the sys_id of the attachments?"
In short, you cannot get the sys_id of a record that has not yet been created. The sys_id is provisioned to the sys_attachment records when the form is submitted and then they are committed to the database.
One suggestion based on your requirements could be that you create a Case Task (in your script) on the Parent of your Lifecycle Event and associate the sys_attachment records to that Case Task. You could then write a script to Copy the Attachments from the Case Task to the Case and close out the Case Task.
This is of course a roundabout way of doing it. In this scenario, I would be seriously considering if we need to be submitting a record producer to do this. Is there another method that we can use? Should we create a custom widget to handle this? If the users need to add an attachment, why don't they have access to the ticket on the portal? etc. Some elaboration on your use case and why it needs to happen via a record producer would be useful so suggestions can be made.
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 02:00 PM
Not sure if I am tracking your question entirely... you could create a BR that runs on update that copies attachments from one table to another. If this gives you duplicates, here is a fix. Also, assuming you already know this, but mentioning it only because I don't see the column in your screenshot. You can pull in the attachment sys_id onto that sys_attachment table from the personalize list option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 02:56 PM
Hey
To answer your questions: "So my question is, how do I determine the table_sys_id of an attachment which is not associated to a generated record when the record producer is submitted? Or how do I determine the sys_id of the attachments?"
In short, you cannot get the sys_id of a record that has not yet been created. The sys_id is provisioned to the sys_attachment records when the form is submitted and then they are committed to the database.
One suggestion based on your requirements could be that you create a Case Task (in your script) on the Parent of your Lifecycle Event and associate the sys_attachment records to that Case Task. You could then write a script to Copy the Attachments from the Case Task to the Case and close out the Case Task.
This is of course a roundabout way of doing it. In this scenario, I would be seriously considering if we need to be submitting a record producer to do this. Is there another method that we can use? Should we create a custom widget to handle this? If the users need to add an attachment, why don't they have access to the ticket on the portal? etc. Some elaboration on your use case and why it needs to happen via a record producer would be useful so suggestions can be made.
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 06:46 AM
Thanks Ethan,
I had a feeling that the table sysId was generated then. Ended up taking a different approach based on that confirmation and your suggestion. Much appreciate your taking the time to respond!
Thanks,
Shawn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 02:36 PM
I know this is an old thread but the above direction is not true, or is no longer true.
When a user attaches a file to a record producer, the attachment is created in the sys_attachment table with a table_sys_id of the target record. Once the RP is submitted the resulting record sys_id will match the table_sys_id of the attachment.
I believe SN is creating the target record while the form is being filled out and only committing on submission - similar to when we click Create New on a table but have not yet clicked Save.
So in the record producer script you can use current.sys_id and use that to query or manipulate the attachment.
This is not the same behavior in an order guide
If you are filling out a record producer that is in an order guide, the attachment is still created in the sys_attachment table but is assigned a temporary tabler_sys_id that is only updated to match the target record sys_id on submission. I do not know if you can refer to that temp table_sys_id in the record producer script.