How to programmatically Checkout KB Article via Scripted API? SOLVED

gabriele5
Kilo Explorer

SOLVED: This is how the working script looks like

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
	var sysId = request.pathParams.sys_id;
	var isDialog = new KBCommon().isStackNameDialog();
	var versioningEnabled = new KBCommon().isVersioningEnabled();
	var currentKb = new GlideRecord('kb_knowledge');
	currentKb.get(sysId);
	var canCheckout = new KBVersioning().canCheckout(currentKb);
	var newKb = new KBVersioning().checkout(currentKb);//NOTE: after execution, currentKb is the new article Object

	return {
		"new_id" : currentKb.sys_id, 
		"workflow" : currentKb.workflow_state,
		"display_number" : currentKb.display_number
		//other parameters you may need
	};
})(request, response);

I'm looking forward to programmatically Checkout a KB Article via Scripted API.

While the overall concept and workflow are rather clear and straightforward, I cannot figure out exactly which parameters of the "current" variable are actually evaluated by the CanCheckout() function in the KBVersioningSNC script.

I've tried to pass the sys_id of the article, the user_id of the user running the query, an array containing both, creating a GlideRecord (probably in the wrong way, though) but it always results in "false" as result.

As far as I understood, the function evaluates the state of the article and whether the user has or has not the rights to Checkout the article (both conditions already verified, in the UI there is the Checkout button), but I am not quite sure how to pass these variables to the CanCheckout() function via Scripted API.

Any hint would be much appreciated.

Thanks.

2 REPLIES 2

sachin_namjoshi
Kilo Patron
Kilo Patron

You can look into OOB UI action code for checkout on kb_knowledge table.

 

var newRecord = new KBVersioning().checkout(current);

 

You need to pass KB article object in above checkout method.

 

Regards,

Sachin

Thanks for your input, very valuable.

I solved the issue - posting the solution in the main post for future reference.