Attach a file in Catalog Item as attachment and alert while submit

SNOW46
Tera Contributor

Hi All,

I want to attach one Excel Sheet as an attachment in one Catalog Item so that whenever form loads the attachment will be visible and any user can download it.

And once the user downloads the attachment will fill it up and again attach the same.

While clicking on Submit I want an alert to be popup if user forgets to attach the file in the Catalog Item.

Can anyone let me know how to achieve this?

 

 

Thanks,

SNOW@Das

17 REPLIES 17

Slawek_Radziewi
Kilo Sage

Just add link to attachment, file in item description. 

In order to get alert when submitting you will need add Catalog Client Script like this

function onSubmit() {
	
	var cat_id = gel('sysparm_item_guid').value;
	
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "sc_cart_item");
	gr.addQuery("table_sys_id", cat_id);
	gr.query();
	if (!gr.next()) {
		g_form.addErrorMessage(getMessage('Alert You want'));
		return false;
	}
	
}

Hi Slawek,

You mean to say that I need to add the attachment in the Catalog Item Description field and in the script you have mentioned i have some doubt.

find_real_file.png

 

The Catalog Client will be defined OnSubmit and as per the below script:

function onSubmit() {
	
	var cat_id = gel('sysparm_item_guid').value;
	
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "sc_cart_item");
	gr.addQuery("table_sys_id", cat_id);
	gr.query();
	if (!gr.next()) {
		g_form.addErrorMessage(getMessage('Alert You want'));
		return false;
	}
	
}

What value should I mention in place of "table_name" and "table_sys_id"?

 

Kindly please let me know?

 

Regards,

SNOW@Das

Hi 

Yes you are right. 

table_name is the coloumn name. keep it as it is.

So you mean to say I should not make any changes in the Script?

I will keep it as it is and the Method will be only Onsubmit?

Correct me if I am wrong?