spfx : Why it does't execute line by line

Aniruddha Aditya 316 Reputation points
2021-02-23T13:47:49.597+00:00

Where am I doing wrong?

So, I have created an spfx extension where I need to do few checks. All working fine except the code jumps from randomly. Now the execution of the code should get me D, A, B and C but it picks randomly, Sometimes C, D A B.

and thus am not able to build by business rules. The java script always gets first preferences.

For exampleL
const getListUrl: string = this.context.pageContext.web.absoluteUrl + "/_api/web/lists/GetByTitle("+BannerConfigurationList+")/items";
this.context.spHttpClient.get(getListUrl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
if (response.status === 200) {
response.json().then((responseJSON) => {
if (responseJSON != null && responseJSON.value != null) {
Get me D

const getListUrl: string = this.context.pageContext.web.absoluteUrl + "/_api/web/lists/GetByTitle("+BannerConfigurationList+")/items";
this.context.spHttpClient.get(getListUrl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
if (response.status === 200) {
response.json().then((responseJSON) => {
if (responseJSON != null && responseJSON.value != null) {
Get Me A

const getListUrl: string = this.context.pageContext.web.absoluteUrl + "/_api/web/lists/GetByTitle("+BannerConfigurationList+")/items";
this.context.spHttpClient.get(getListUrl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
if (response.status === 200) {
response.json().then((responseJSON) => {
if (responseJSON != null && responseJSON.value != null) {
Get Me B

const getListUrl: string = this.context.pageContext.web.absoluteUrl + "/_api/web/lists/GetByTitle("+BannerConfigurationList+")/items";
this.context.spHttpClient.get(getListUrl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
if (response.status === 200) {
response.json().then((responseJSON) => {
if (responseJSON != null && responseJSON.value != null) {

Get Me C

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,052 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-02-24T02:32:03.42+00:00

    These are all asynchronous requests, so the order of request return values may not be returned in the order of request. These requests can be set as synchronous requests, and the request results will be returned in order.

    1. async function
    2. Promise

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments