Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I have this unbound action configured:
{
"name": "DeleteWorkspacesIfEmpty",
"importName": "DeleteWorkspacesIfEmpty",
"description": "Delete all Workspaces if empty",
"parameters": [
{
"name": "workspaces",
"type": "String",
"isNullable": false,
"isCollection": true
}
],
"returnType": {
"type": "String",
"isNullable": false,
"isCollection": false
}
}
With this JS:
function action_DeleteWorkspacesIfEmpty(data, params) {
var WorkspaceFunction = Java.type('at.techsoft.twice.WorkspaceFunction');
var workspaceFunction = new WorkspaceFunction();
workspaceFunction.deleteWorkspacesIfEmpty(data, params);
}
And this Java Code:
public ActionResult deleteWorkspacesIfEmpty(ActionProcessorData data, Map<String, Parameter> params) throws ODataApplicationException, JSONException {
Object obj = params.get("workspaces").getValue();
List<String> deletedWorkspaces = new ArrayList<>();
EntityCollection entityCollection = new EntityCollection();
if (obj instanceof ArrayList) {
List<String> workspaces = (List<String>) obj;
for(String workspace : workspaces) {
EPMWorkspace epmWorkspace = QueryHelper.findWorkspace(workspace);
if (epmWorkspace != null) {
try {
if (EPMWorkspaceHelper.manager.getObjectsInWorkspace(epmWorkspace, Persistable.class).size() == 0) {
PersistenceHelper.manager.delete(epmWorkspace);
deletedWorkspaces.add(workspace);
}
} catch (WTException e) {
throw new BadRequestException(e);
}
}
}
}
ActionResult actionResult = new ActionResult();
JSONObject jsonObject = new JSONObject();
jsonObject.put("deleted", deletedWorkspaces);
EntityAttribute retEntity = new EntityAttribute("Edm.String", null, PropertyValueType.PRIMITIVE, jsonObject.toString());
actionResult.setReturnedObject(retEntity);
return actionResult;
}
The Problem is when I request this Action, the response is:
{
"error": {
"code": "NOT_SUPPORTED",
"message": "The feature being exercised is not supported"
}
}
And in the log file the Error is:
2020-08-14 09:56:24,281 ERROR [ajp-nio-127.0.0.1-8010-exec-5] com.ptc.odata.core.entity.processor.ActionProviderProcessor wtadmin - Action implementation must return a ActionResult: org.apache.olingo.commons.core.edm.EdmActionImpl@25896e4
2020-08-14 09:56:24,297 ERROR [ajp-nio-127.0.0.1-8010-exec-5] wt.servlet.ServletRequestMonitor.request wtadmin - 2020-08-14 09:55:41.496 +0200, 4eihaj13;kdtx4n9o;12640;ht9eo6;1803, wtadmin, 10.2.150.48, /Windchill/servlet/odata/v1/TWICE/DeleteWorkspacesIfEmpty, -, POST, 501, 0.015625, 42.7960182
Does anyone know what I am doing wrong?
Solved! Go to Solution.
I forgot a return in my JavaScript part.
Wow Good to know:) . can you please post your working code here please.
Also, Pl tell that "How did you use
"name": "DeleteWorkspacesIfEmpty",
"importName": "DeleteWorkspacesIfEmpty",
this Import Name.
I am using the same code as yours and getting error :
I got a similar error, it was due to making a GET request instead of POST.