How to get cart ID

Kai Schmidt
Tera Contributor

I have a catalog item in portal where the user has to upload a csv file into ootb attachment section. Currently I face an issue with cart id which is needed to get the attachment record, in portal I cannot get cart id. I need the attachment in order to check existence, proper naming and type (.csv) of attachment. 

Who has an idea?

3 REPLIES 3

Community Alums
Not applicable

Hi @Kai Schmidt ,

Unfortunately it is not possible in serviceportal. The serviceportal uses the cart API and therefore does not pre-generate any IDs as it just passes the catalog item details along when you add an item to the cart.

Here is the workaround:

1. Customize "SC Catalog Item" widget's client script to include "g_form.generatedItemGUID = $scope.data._generatedItemGUID;":

var g_form;
	$scope.$on('spModel.gForm.initialized', function(e, gFormInstance){
		if (gFormInstance.getSysId() != -1 && gFormInstance.getSysId() != c.getItemId())
			return;
		g_form = gFormInstance;
		
		$timeout(function() {
				$rootScope.$emit('spModel.gForm.rendered', g_form);
		}, 175);
		
		// This runs after all onSubmit scripts have executed
		g_form.$private.events.on('submitted', function(){
			if ($scope.data.sc_cat_item.item_action === "order")
				getOne();
			else if ($scope.data.sc_cat_item.item_action === "add_to_cart")
				addToCart();
			else if ($scope.data.sc_cat_item.item_action == "update_cart")
				updateCart();
		});
		
		//2019-03-04 James McWhinney
		g_form.generatedItemGUID = $scope.data._generatedItemGUID;
		
		
	});

2. Use g_form.generatedItemGUID in your catalog client script.

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

 

Community Alums
Not applicable

Hi @Kai Schmidt ,

Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.

Thanks,
Sandeep

var cat_id = g_form.generatedItemGUID;
    alert(cat_id);
 
It is showing undefined even after widget customization