get the Cart Item ID for a Catalog Item WITHIN the workspace

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 and get the correct sys_id. 
This will give me the sys_id of the new sc_cart_item (not the Catalog Item) so I can do some checking in the sys_attachment table.

 

Doing some playbook work via a workspace.  Part of it is to call an existing Catalog Item that does some attachment checking.  I didn't really worry as it works.  Or so I thought......

Got the step inside the playbook, add my attachment and I get a console error (hmmm - worrying)  and then the validation error (botherations).

I look, and none of the steps below are able to get the sys_id of the cart item and I cannot fathom a way to get it either

Anyone got any idea how to get it - I am going to work on the basis that there is no Cart Widget on the "Place Request" from within a Catalog Item is used and hence it is not doing all the work the code below relies on


Changing the "Portal Settings" from Submit to Request or Order has no bearing - have tried just in case

 

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;
	}
}

 

 

2 REPLIES 2

vandanasaluja
Tera Contributor

your codew is dependent on service portal cart widget .all of this exist when you are in portal not in workspace .For Workspace you need to write .for ex using br 

function executeRule(current, previous) {

var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', 'sc_cart_item');
att.addQuery('table_sys_id', current.sys_id);
att.query();

if (!att.hasNext()) {
gs.addErrorMessage('Attachment is mandatory.');
current.setAbortAction(true);
}

})();

Your code is a BR - not really a good experience for a user and doubtful it will work in this scenario
This needs to be a client side routine.  The code we use is used by quite a few Catalog Items for attachment checking and until now not been a problem.  
It is potentially going to be a bit of an issue as the client is now either incorporating more Playbooks or modifications to call additional Catalog Items, so any that have attachment checking could be in trouble.
So, I need to get the sys_id of the sc_cart_item somehow

So my item inside the workspace

JulianP32954866_0-1769521721842.png


The sys_attachment table

JulianP32954866_1-1769521741161.png



So when you attach a file SNC knows the sys_id of the sc_cart_item.
My code when in the portal or classic view can get that (because of g_form or what is provided by the portal widget) and then run what I want and present the user with information straight away

It is just where are they putting that info now so I can add another option to go and search for it - it clearly exists for them to use it.......