Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract field from Javascript object in google apps script

I am very new at this and the answer is probably very simple, but please help.

I get the following returned from a query, this is a jsonParse of the result

{"totalSize":1,
"done":true,
"records":
    [{"attributes": 
    {
        "type":"Account",
        "url":"/services/data/v21.0/sobjects/Account/001C0000012Z8Y5IAK"
    },
    "Id":"001C0000012Z8Y5IAK"
    }] 
}

How do I extract the Id at the end into a variable when totalSize = 1?

like image 736
Jim F Avatar asked Feb 05 '26 13:02

Jim F


1 Answers

objectName.records[0].Id will do the trick. Increment records index appropriately.

Sample -

var sforceResponse = {"totalSize":1,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v21.0/sobjects/Account/001C0000012Z8Y5IAK"},"Id":"001C0000012Z8Y5IAK"}]}

sforceResponse.records[0].Id //this variable contains the Id. 
like image 56
Arun Nagarajan Avatar answered Feb 08 '26 20:02

Arun Nagarajan