on 2024 Aug 29 3:02 PM
Hello,
I'm working on screen personas and I want to apply an example code to get some extra data on page.
I modify this code and get error. In my opinion I missing the credentials and authentitacion but how to improve it?
if (session.idExists('wnd[0]/usr/txtPersonas_168387506699773')) {
if (session.findById('wnd[0]/usr/txtPersonas_168387506699773').text != '') {
var altID = session.findById('wnd[0]/usr/txtPersonas_168387506699773').text;
session.utils.log(altID);
//Create the request object
var http = new XMLHttpRequest();
//Specify the type of request, the url and if the request should be handled
asynchronously or not
http.open(
'GET',
"https://xxxx.xxx.xxx.xxxx/sap/opu/odata4/sap/api_handlingunit/srvd_a2x/sap/handlingunit/0001/Handlin...
itAlternativeID?$filter=Warehouse eq ‘1050’ and EWMHndlgUnitAltvID eq ‘” +
altID +“’”,
false
);
//set request header attributes
http.setRequestHeader(‘DataServiceVersion’, ‘2.0’);
http.setRequestHeader(‘Accept’, ‘application/json’);
//Send the request
http.send();
//Process the response
if (http.readyState == 4 && http.status == 200) {
//The response is available in the http.response property
session.utils.log(http.response);
try {
var HU = JSON.parse(http.response).value[0].HandlingUnitExternalID;
session.utils.log(HU);
session.findById(‘wnd[0]/usr/subX:/SCWM/SAPLRF_INQUIRY_PM:0200/txt/SCWM/S_RF
_SELECTION-RFHU’).text = HU;
} catch (error) {
session.utils.log(‘HU number could not be determined based on alternative HU
ID ‘ + altID);
session.utils.alert(‘HU number could not be determined based on alternative
HU ID ‘ + altID);
}
} else {
session.utils.log(‘OData API query failed’);
session.utils.alert(‘Odata API query failed’);
}
session.utils.log(‘API call finished’);
} else {
session.utils.log(‘API NOT called’);
}
}
Request clarification before answering.
Dear @Jacekkp111
I looked through your code and I have a few words to say:
So to resolve your issue I suggest using a try catch block around the send() function and dig through the stack trace because I don't think it has to do with auth credentials but with the way you construct your URL.
Also please make sure to insert your code in a proper format. The editor of the SAP community forum has a code tag. It makes reading the code much easier 😉
@Giuseppe432Can you please post your code? Or better yet open a new question so we don't have 2 issues within one post 🙂
Kind regards radinator
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you for your suggestions, I think that the problem in this code at the moment is CORS, do you know how to get around it? access to XMLHttpRequest at 'https://myxxxx-api.s4hana.cloud.sap/sap/opu/odata/sap/API_PROD_ORDER_CONFIRMATION_2_SRV/ProdnOrdConf...' from origin 'https://myxxxx.s4hana.cloud.sap' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. The error message tells us that a web page (likely running JavaScript) at https://myxxxx.s4hana.cloud.sap is trying to make an XMLHttpRequest (a type of HTTP request used by JavaScript) to a different domain: https://myxxxx-api.s4hana.cloud.sap.
@Jacekkp111If your issue is the CORS error message you can avoid this by sending a CORS allow header as described in this SO posting.
User | Count |
---|---|
68 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.