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

11 REPLIES 11

g_form.generatedItemGUID not working even after widget customization, it is giving undefined. I'm currently in Utah

var cat_id = g_form.generatedItemGUID;
    alert(cat_id);

JulianP32954866
Tera Expert

So, I have code that can work on the pages without editing the Widget
It works fine for items in the portal and there is the existing "desktop" code you can call using the same function name.

 

My new problem, Workspace.  None works -arghh

 

function onLoad() {
}

// this function has changed. Originally it was using the parentScope.$parent options when written on a fresh PDI
// on a client that instantly failed. Not sure what version of the Cart Widgets they are using, but removing the $parent
// works.  
// if this fails at another customer, do some checking and work out where the scope is located and adapt here as necessary

getCartAttachmentID = function () {
	try {
		debugger;
		var refID = getIDFromScope('top', false) || '';
		if (refID == '') {
			refID = getIDFromScope('parent', false) || '';
		}
		if (refID == '') {
			refID = getIDFromScope('window', false) || '';
		}

		if (refID == '') {
			refID = getIDFromScope('top', true) || '';
		}
		if (refID == '') {
			refID = getIDFromScope('parent', true) || '';
		}
		if (refID == '') {
			refID = getIDFromScope('window', true) || '';
		}

		if (refID == '') {
			console.error('getCartAttachmentID : scope : Unable to retrieve Cart ID : error : no data retrieved');
		}
		return refID;

	} catch (e) {
		console.error('getCartAttachmentID : scope : Unable to retrieve Cart ID : error : ' + e.message);
	}



}

getIDFromScope = function (strParent, bolParent) {
	try {
		bolParent = bolParent || false;
		var parentScope;
		if (strParent == 'top') {
			parentScope = top.window.angular.element('#sc_cat_item').scope();
		} else if (strParent == 'parent') {
			parentScope = parent.window.angular.element('#sc_cat_item').scope();
		} else {
			parentScope = window.angular.element('#sc_cat_item').scope();
		}

		if (bolParent) {
			return parentScope.$parent.c.data.sc_cat_item._attachmentGUID || '';
		} else {
			return parentScope.c.data.sc_cat_item._attachmentGUID || '';
		}
	} catch (e) {
		return;
	}
}