# Need help understanding input type (String or something else) to Java script, Is there a way to debug Java script?

**URL:** <https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143>\
**Category:** Ask for Help\
**Created:** [September 5, 2024, 5:23am UTC](https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143 "2024-09-05T05:23:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [September 5, 2024, 5:23am UTC](https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143/1 "2024-09-05T05:23:13Z")

</div>

Hi Guys,

I am not an expert of Java script but I used chat got to get a java script which will take input as value from my template column which is basically my API mutation

EX: of a row of my template column

```auto
{
      "kind": "add-row-to-table",
      "tableName": "native-table-jWEMMuChAFBW3berD6UM",
      "columnValues": {
        "Name": "ughRV70bRrmMxq59sNLtCg",
        "hUS5E": "Prajwal Devaraj",
        "3Fbda": "false",
        "WBVZ6": "false",
        "TeIW1": "false",
        "VA1A4": "ughRV70bRrmMxq59sNLtCg"
      }
    }

```

**I am passing this column as p1 to my java script below**

```auto
// Global array to hold the combined column values from all rows
let jsonArray = [];

function processCreatorAPIMutation(p1) {
  try {
    // Check if p1 is a string (i.e., needs to be parsed) or an object
    let rowObject = typeof p1 === "string" ? JSON.parse(p1) : p1;

    // Check if the rowObject has 'columnValues', and push its value to the global jsonArray
    if (rowObject && rowObject.columnValues) {
      jsonArray.push(rowObject.columnValues);
    }
  } catch (error) {
    console.error("Error parsing JSON:", error, "Input data:", p1);
  }

  return jsonArray; // Return the combined array after each invocation
}

// The variable 'p1' will be automatically passed from Glide.
// The global jsonArray will accumulate the results from each row.
let result = processCreatorAPIMutation(p1);
console.log(result); // This will output the cumulative JSON array of column values

```

Multiple tries lead me to this script which gives me the following error

![Screenshot 2024-09-05 at 10.52.28 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/7/a7ae70b9a9255b4238701fdb4dc89bc8ddad3189.png)

**Want to know what is the input which is given as p1, is it a string value that is sent internally by glide?**

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 5, 2024, 11:23pm UTC](https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143/2 "2024-09-05T23:23:23Z")

</div>

Your function doesn’t use a return line to actually return something to the column. Your last two lines can just be:

`return processCreatorAPIMutation(p1)`

Also, it looks like you’re trying to return an array there. You should turn that into a string before doing the return line.

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [September 6, 2024, 4:36am UTC](https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143/3 "2024-09-06T04:36:46Z")

</div>

Thank you replying @ThinhDinh

user Chat GPT to make the changes you asked

// Global array to hold the combined column values from all rows  
let jsonArray = ;

function processCreatorAPIMutation(p1) {  
try {  
// Check if p1 is a string (i.e., needs to be parsed) or an object  
let rowObject = typeof p1 === “string” ? JSON.parse(p1) : p1;

```
// Check if the rowObject has 'columnValues', and push its value to the global jsonArray
if (rowObject && rowObject.columnValues) {
  jsonArray.push(rowObject.columnValues);
}

```

} catch (error) {  
console.error(“Error parsing JSON:”, error, “Input data:”, p1);  
}

// Convert jsonArray to a JSON string before returning it  
return JSON.stringify(jsonArray); // Return the combined array as a string after each invocation  
}

// The variable ‘p1’ will be automatically passed from Glide.  
// The global jsonArray will accumulate the results from each row.  
return processCreatorAPIMutation(p1);

It still returns me only the corresponding row value as JSON object.

Doesn’t return me all rows combined value as a string.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 6, 2024, 11:50am UTC](https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143/4 "2024-09-06T11:50:17Z")

</div>

What do you mean by “all rows combined”? It would only run on its own row.

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [September 7, 2024, 10:49am UTC](https://community.glideapps.com/t/need-help-understanding-input-type-string-or-something-else-to-java-script-is-there-a-way-to-debug-java-script/76143/5 "2024-09-07T10:49:25Z")

</div>

Hi @ThinhDinh ,

I understand now that it processes only single row and outputs the rows values.

But it does not iterate through every array to return me the JSON array of all items values.

Regards,  
Dilip
