cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Custom OData Action throws Error

dullnigAlex
12-Amethyst

Custom OData Action throws Error

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?

 

 

ACCEPTED SOLUTION

Accepted Solutions

I forgot a return in my JavaScript part.

View solution in original post

4 REPLIES 4

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 :

"message""Cannot find EntitySet, Singleton, ActionImport or FunctionImport with name 'GetParts'."
Pl help.

 

 

bjoyce
5-Regular Member
(To:sidsinha16)

I got a similar error, it was due to making a GET request instead of POST.

Announcements

Top Tags