Attachment file type client script - g_form.getUniqueValue help

Hannah C
Giga Expert

Hello! I am trying to write a client script to work in the Service Portal that doesn't allow a user to submit the catalog item without an Excel file attached.

I've seen some community posts on this and they all say to use g_form.getUniqueValue() and then use that to query the sys_attachment table:

var sys_id =  g_form.getUniqueValue()

var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_name', 'sc_cat_item');
gr.addQuery('table_sys_id', sys_id);
gr.query();

I added console.log(sys_id); to see what sys_id the g_form.getUniqueValue() was returning. Then I checked the sys_id of table_sys_id column on the sys_attachment table for the attachment I just added and they are different. Why is that? Any other solutions to query the attachment table in a client script?

Thanks!

4 REPLIES 4

asifnoor
Kilo Patron

Can you compare the sys_id of the attachment with the value of g_form.getUniqueValue() and check.

They are different. The value returned by g_form.getUniqueValue() is the sys_id of the catalog item.

So that is correct only, right.

Check the table_sys_id that is presnet in sys_attachment table. Check which catalog item it is ponting to?

It is not pointing to any catalog item. Every time I attach something to this catalog item the table_sys_id is a new different one. How is this table_sys_id field getting populated? Is it something to do with the attachment is on the sc_cart_item table since it hasn't been submitted yet?