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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Error in executing the copied service code, JSON Server error HTTP 404

shindemayur
13-Aquamarine

Error in executing the copied service code, JSON Server error HTTP 404

Hello,

I have  a thing "ptc-windchill-demo-thing" which is imported /created at time of Navigate Installation process.

Their is a service in that Thing   , named as GetPartByNumber.

 

I just created another thing just like "ptc-windchill-demo-thing" and created a service same as "GetPartByNumber".

When I run the service I get error as:

JSON Server error HTTP 404

 

The JS code in service is :

var numbers = {}; //To be used to get cost data ERP
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
    infoTableName: "InfoTable",
    dataShapeName: "ptc-part-demo-shape"
});
if (number) {
    occurrencePathFilter = occurrencePathFilter? occurrencePathFilter : occurrencePathFilterFromTree;

var dataShapeFields = result.dataShape.fields;
var properties = '';
for (var fieldName in dataShapeFields) {
    properties += ',' + fieldName;
}
properties = properties.replace(/--/g, ".");
var selectedTypeId = typeId == null ? "wt.part.WTPart" : typeId;
var params = {
    type: 'GET',
    url: me.getRestUrl() + "/structure/objects",
    queryParams: {
      '$select': properties,
      '$filter': "number eq '" + number + "'",
      'navigationCriteria': navigationCriteria,
      'typeId': selectedTypeId
    }
};
// result: JSON
var jsonResult = me.processJSONRequest(params);
var obj = me.ConvertJSONToObject({json: jsonResult.items[0], fields: dataShapeFields});
obj.id = obj.objectId = jsonResult.items[0].id;
obj.treeId='/';
obj.parentId = '';
obj.usesOccurrenceIdentifier = '';
if (!occurrencePathFilter || occurrencePathFilter === '/') {
    result.AddRow(obj);
    numbers[obj.number] = true;
}
var queryParams = {
  'levels': '' + levels,
  '$select': properties,
  '$expand': "occurrences",
  'inline': "true",
  'navigationCriteria': navigationCriteria
}
if (occurrencePathFilter && occurrencePathFilter != '/') {
  queryParams['$filter'] = "path eq '" + occurrencePathFilter + "'";
}
var params = {
    type: 'GET',
    url: me.getRestUrl() + "/structure/objects/" + encodeURIComponent(obj.id) + "/" + tree,
    queryParams: queryParams
};
// result: JSON
var jsonResult = me.processJSONRequest(params);
if (result.getRowCount() > 0 && jsonResult.items.length > 0) {
    result.getRow(0).hasChildren = true;
}
if (!occurrencePathFilter || occurrencePathFilter != '/') {
    for (var i = 0, l = jsonResult.items.length; i < l; i++) {
        var json = jsonResult.items[i];
        var obj = me.ConvertJSONToObject({
            json: json /* JSON */,
            fields: dataShapeFields /* JSON */
        });
        var objs;
        if(obj.array) {
            objs = obj.array;
        } else {
            objs = [];
            objs.push(obj);
        }
        for(var j = 0, m = objs.length; j < m; j++) {
            var obj = objs[j];
            if (!occurrencePathFilter || obj.treeId == occurrencePathFilter) {
                obj.cost = Math.floor(Math.random() * (1499.00));
                  obj.quantityInStock = Math.random() * (1000);
                result.AddRow(obj);
                numbers[obj.number] = true;
            }
        }
    }
}

}

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

 

Just to clarify, some parts of the JS were edited by yourself correct? I don't have the original service at hand.

 

The 404 you're getting is from a attempt to perform a rest call on a url that doesn't exist.

I would troubleshoot this by first checking if the first JSON result is valid and commenting out the second.

If the first JSON result has a problem:

url: me.getRestUrl() + "/structure/objects/" + encodeURIComponent(obj.id) + "/" + tree,

will attempt a request on a url that may not exist resulting in the 404 you're seeing.

 

Regards,

Pascal

 

View solution in original post

1 REPLY 1

Hello,

 

Just to clarify, some parts of the JS were edited by yourself correct? I don't have the original service at hand.

 

The 404 you're getting is from a attempt to perform a rest call on a url that doesn't exist.

I would troubleshoot this by first checking if the first JSON result is valid and commenting out the second.

If the first JSON result has a problem:

url: me.getRestUrl() + "/structure/objects/" + encodeURIComponent(obj.id) + "/" + tree,

will attempt a request on a url that may not exist resulting in the 404 you're seeing.

 

Regards,

Pascal

 

Top Tags