Seeking help verifying SAP portal login in Adobe form using JavaScript, need alternative solutions | Community
Skip to main content
February 19, 2024
Solved

Seeking help verifying SAP portal login in Adobe form using JavaScript, need alternative solutions

  • February 19, 2024
  • 1 reply
  • 1119 views

When a button is clicked in my Adobe Interactive Form, I aim to verify user credentials for the SAP portal using JavaScript, but I'm not receiving the expected status back. Here's the code I'm using:

when button CLICK event in the adobe digital form 

var cPortalUrl = "https://nspek.com:50001/irj/portal?j_user= <userid>&j_password=<password>";

var cStatus;

var pingportalstatus =
function PortalPing (cPortalUrl){
    var xmlHttp = new XMLHttpRequest();

xmlHttp.onreadystatechange = function()  

     { 

          cStatus =  xmlHttp.status;

     };


    xmlHttp.open("GET", cPortalUrl, false);
    xmlHttp.send();

return xmlHttp.status;
};

Any advice on why cStatus isn't being populated would be appreciated.

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Hi, 

 

I think the issue is that the xmlHttp.status property is not guaranteed to be populated synchronously in your code due to the asynchronous nature of XMLHttpRequest. It's populated asynchronously when the state of the XMLHttpRequest changes. 

You can learn more here about how this works: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status.

 

I would use FETCH instead of XHR due to performance reasons. It would be something like this:

var cPortalUrl = "https://nspek.com:50001/irj/portal?j_user=<userid>&j_password=<password>"; function PortalPing(cPortalUrl, callback) { fetch(cPortalUrl) .then(function(response) { if (response.ok) { callback(response.status); } else { callback(response.status); } }) .catch(function(error) { console.error("Fetch error:", error); callback(null); // Pass null status to callback to indicate error }); } // Example usage PortalPing(cPortalUrl, function(status) { if (status !== null) { console.log("Status:", status); } else { console.log("Error occurred during fetch."); } });


Hope this helps.

1 reply

EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
February 19, 2024

Hi, 

 

I think the issue is that the xmlHttp.status property is not guaranteed to be populated synchronously in your code due to the asynchronous nature of XMLHttpRequest. It's populated asynchronously when the state of the XMLHttpRequest changes. 

You can learn more here about how this works: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status.

 

I would use FETCH instead of XHR due to performance reasons. It would be something like this:

var cPortalUrl = "https://nspek.com:50001/irj/portal?j_user=<userid>&j_password=<password>"; function PortalPing(cPortalUrl, callback) { fetch(cPortalUrl) .then(function(response) { if (response.ok) { callback(response.status); } else { callback(response.status); } }) .catch(function(error) { console.error("Fetch error:", error); callback(null); // Pass null status to callback to indicate error }); } // Example usage PortalPing(cPortalUrl, function(status) { if (status !== null) { console.log("Status:", status); } else { console.log("Error occurred during fetch."); } });


Hope this helps.

Esteban Bustamante
BorowskiAuthor
February 20, 2024

This works! How did you learn that - got experience creating digital forms?

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 20, 2024

I'm glad to hear it worked! This is more related to Javascript skills. If you're interested in furthering your JavaScript skills, reviewing asynchronous and synchronous concepts, especially in the context of handling HTTP requests, can be very helpful.

Cheers!

Esteban Bustamante