How do I get the sys_id of sc_cart_item before item is added to user's cart?

bjonesy
Tera Contributor

I want to validate that a user has attached a quote (e.g. uploaded .docx) to a catalog item before they submit the item to their cart.  To do this I want to check the sys_attachment table for any attachments.  When a user uploads the attachment, but before they add the item to their cart, SNow puts a record in sys_attachment with:

Table name = sc_cart_item

Table sys ID = <GUID of sc_cart_item instance>

The issue is SNow has not committed the sc_cart_item to the table until the user adds it to their cart so I can't get the sys_id of the sc_cart_item to check the sys_attachment table.  But obviously the session has the GUID since it inserted the GUID to the sys_attachment table.  Anyone know how to get a reference to the sc_cart_item GUID before the user submits the item to their cart?

Thanks in advance.

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Try g_form.getParameter("sysparm_item_guid") in client script


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Try g_form.getParameter("sysparm_item_guid") in client script


Please mark this response as correct or helpful if it assisted you with your question.

Hannah C
Giga Expert

Hi! Do you happen to have the full client script you used to achieve this? I am trying to accomplish the same thing but having no luck. Thanks!

bjonesy
Tera Contributor

Hi Hannah,

Here is the onSubmit client script.  Hope it helps!

 

function onSubmit() {
	
	g_form.clearMessages();
	
	var hasAttachment = false;
	var hasAttGA = new GlideAjax('CatalogAttachmentUtil');
	hasAttGA.addParam('sysparm_name', 'hasAttachment');
	hasAttGA.addParam('sysparm_table_name', 'sc_cart_item');
	hasAttGA.addParam('sysparm_table_sys_id', g_form.getParameter("sysparm_item_guid"));
	
	hasAttGA.getXMLWait();
	var myObj =  hasAttGA.getAnswer();
	var attachResp = JSON.parse(myObj);

	//g_form.hideFieldMsg('attach_quote',true);
	if(!attachResp.hasAttachment){
		//g_form.showErrorBox('attach_quote','A quote attachment is required.  Please attach a quote.',true);
		g_form.addErrorMessage('A quote attachment is required.  Please attach a quote using the paperclip icon.');
	}else{
		hasAttachment = true;
	}
	return hasAttachment;
   
}

Thank you so much for responding that was very nice!! Is this just for the platform side? I am trying to have this work on the portal so I think I will need to try something else