cancel
Showing results for 
Search instead for 
Did you mean: 

Getting URL of called oData service

matma24
Participant
0 Kudos

Hello guys,

I've been using following API to update Commercial Projects: https://api.sap.com/api/_CPD_SC_PROJ_ENGMT_CREATE_UPD_SRV/resource

I wanted to do "mass update" of ProjectStage which can be done by sending a PATCH.

I've been doing that in my UI5 app but unfortunately I have come to error handling -> to handle the errors I would like to know on which entity the error occurred. I'm sending 100 requests in a deferredGroup but the message of an error is not returning project ID for which the PATCH was requested.

The body of response is:

{
  "error": {
    "code": "string",
    "message": {
      "lang": "string",
      "value": "string"
    },
    "innererror": {}
  }
}

Which leads me to the point that I am not able to distinguish which Projects were successfully updated and which not.

Is there any way in oModel.update in error callback function to access the URL/ ID of the project of the request so I will be able to figure out which project this error is about?

Quick & similar example:

When I call:

for (var i = 0; i < aProjects.length; i++){
oModel.update("/ProjectSet('" + aProjects[i].id + "')", oChangedValues, {
method: 'MERGE',
success: function(oResponse){

}, 
error:function(oError){
// how can i access aProjects[i].id here of the one that was just called
// simply so i will know to which projectid this error corresponds
}
})
}
View Entire Topic
junwu
Active Contributor

can you assign a different value to changeSetId for each of your request, check if it makes any difference.

matma24
Participant
0 Kudos

I'm not really sure what do you mean? What exactly would it give me? I can send the requests with different changeSetId and I can even create object/array where I will map changeSetId to ProjectID but how in error callback will I be able to access changeSetId/ProjectID to know exactly which ProjectID failed (simply returned 4xx error but query itself isn't "failed")

junwu
Active Contributor
0 Kudos

it is not big change for u, just give it a try,

leave it if you don't want.

junwu
Active Contributor
0 Kudos

how about not using your own deferred group?

in that case, the individual success/error call back will be called(based on the code you shown before), then you should be able to know which entry failed.

matma24
Participant
0 Kudos

As I said above -> it is called but error message does not contain the object that error is about thats why when i send 1000 on those updates then if i get a fail how can I get information about which ProjectID this fail is about.

I've added unique changeSetId but I don't see any difference.

junwu
Active Contributor
0 Kudos

check if you can get projectId in your error function callback.

for (var i = 0; i < aProjects.length; i++){
var projectId=aProjects[i].id; oModel.update("/ProjectSet('" + aProjects[i].id + "')", oChangedValues, { method: 'MERGE', success: function(oResponse){ }, error:function(oError){ // how can i access aProjects[i].id here of the one that was just called // simply so i will know to which projectid this error corresponds } }) }
matma24
Participant
0 Kudos

Nope, it's not solving this problem. I have tried that before, as well with passing the context etc.

junwu
Active Contributor
0 Kudos

can you give a screenshot when you put a breakpoint at the error handler?

i want to check what you have in those closure....

matma24
Participant
0 Kudos

jun.wu5 attached as requested.

junwu
Active Contributor
0 Kudos

are you still using submitchanges?

matma24
Participant
0 Kudos

At this moment I'm doing that in the For loop but if I do deferredGroup and submit changes scope is exactly the same so I can't access project id in callback function anyway.

junwu
Active Contributor
0 Kudos

I tested at my side,

In my case, the individual success/error handler is getting called.

In my for loop, i am doing read call, not sure if it makes any difference( you are doing update call)

can you show me your code again?

matma24
Participant
0 Kudos

Of course it is getting called. What I'm saying is:

Let's say I send 100updates to different projects (simply lets say i send batch with 100 requests), if one the updates goes into error callback how can I know which project id it was since this SAP API mentioned above does not return ProjectId.

junwu
Active Contributor
0 Kudos

dude, show me the code...

matma24
Participant
0 Kudos

The code is literally in the question:

for (var i = 0; i < aProjects.length; i++){
var projectId=aProjects[i].id; oModel.update("/ProjectSet('" + aProjects[i].id + "')", oChangedValues, { method: 'MERGE', success: function(oResponse){ }, error:function(oError){ // how to access aProjects[i].id here -> if the loop run 100x and send 100 requests i simply want to know which ID went into error callback } }) }