Is there a way to get the cart item id in portal

venkatiyer1
Giga Guru

Hi all,

in the normal view of a service catalog item, if you were to try executing g_form.getParameter("sysparm_item_guid")   you would get the cart item id in advance before the item gets submitted.

Is there a way where i can get the cart item id of the item getting submitted in service portal?

1 ACCEPTED SOLUTION

Ahh, yes now I understand.



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.



Maybe you can describe your business logic for this, and I might be able to give you some alternative suggestions?


View solution in original post

10 REPLIES 10

Ahh, yes now I understand.



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.



Maybe you can describe your business logic for this, and I might be able to give you some alternative suggestions?


venkatiyer1
Giga Guru

Hi Lars,



Thanks for your reply and confirming it is not feasible. I did have a back up solution for my problem though i preferred the cleaner approach of using the cart item id as that was more reliable.


Could you share your workaround for this?
I'm having a similar issue

jamesmcwhinney
Giga Guru

We were struggling with this also.
We wanted to check to see if the user had added an attachment, and then use that information in an onChange catalog client script.
We are on London and using the Service Portal for our Service Catalog.

As discussed above in this thread, it seems there is no way to determine the sys_id of the associated sc_cart_item from g_form when using Service Portal.

 

We came up with the below 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.

 

 

Can you share the full code of this Widget and how you use it.