Help

Only first row updating (updateRecordsAsync)

Topic Labels: Scripting extentions
Solved
Jump to Solution
1650 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Kosta_Kondraten
7 - App Architect
7 - App Architect

Trying to take Object returns from my PHP endpoint and populate the rows of a table - only the first row is being populated (aka cell fields in first row only) - here is my code:

// query for every record in "People"
let table = base.getTable("SMS");
let view = table.getView("All");
let query = await view.selectRecordsAsync({fields: ["Contact","URL"]});

var json_payload = [];

let individual_injection = {};


for (let record of query.records) {

    let name = record.getCellValueAsString("Contact");
    let URL = record.getCellValueAsString("URL");

    individual_injection = {
        'ID': record.id,
        'Name': name,
        'URL': URL
    };

    json_payload.push(individual_injection);
}

console.log(JSON.stringify(json_payload));

let response = await remoteFetchAsync('http://147.182.192.192/speech.php', {
    method: 'POST',
    body: JSON.stringify(json_payload),
    headers: {
        'Content-Type': 'application/json',
        'Authorization' : 'Basic d2h5d29udHlvdWNvbm5lY3Q6Y2N1WSAxWWhkIDdsTmkgMzdWSSB5MVlyIDYySEs='
    },
    });

    let body = await response.json();
    console.log(body);

    for (let i = 0; i < body.length; i++) {
        RecordID = body[i].recordID;
        ShortLink = body[i].shortURL;
        LinkID = body[i].linkID;
        await table.updateRecordAsync(RecordID, {
            "LinkID": LinkID,
            "Shortlink": ShortLink
        });       
      }

    console.log("If you see this we have made it home Master Wayne");

    console.log(JSON.stringify(body));

Here is what I see:

As you can see only first row is updated when the script is run but I have checked objects and the values are definately there - it even gets echoed on console log if I review

Thank you!

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

It looks like all the record ids are the same in your payload.

See Solution in Thread

3 Replies 3
kuovonne
18 - Pluto
18 - Pluto

It looks like all the record ids are the same in your payload.

Not the case… I don’t think. This is the JSON.stringify of the load I send to my PHP endpoint - I just checked and I saw multiple Record ID’s - Image 2022-06-20 at 11.59.3...

Never mind… you’re right… I just checked my return and all the RecordID’s are the same… so strange… but this should help me further troubleshoot my problem… thank you!