get mainAddress from a location record using rest ...
# ask-stanley-ai
j
get mainAddress from a location record using rest API
c
AI generated answer (using internal Slack threads):
To get the
mainAddress
from a location record using the REST API, you can use the
GET
method on the
record/v1/location/{id}
endpoint. However, the
mainAddress
field is a subrecord, and the REST API does not directly support subrecords. In the SuiteScript API, you can access subrecords using the
viewSubrecord
method, as mentioned in one of the threads:
locationRec.viewSubrecord('mainaddress');
. But this method is not available in the REST API. As a workaround, you can create a Suitelet or a RESTlet in SuiteScript that retrieves the
mainAddress
subrecord and then call this Suitelet or RESTlet from your external application. Here is a sample SuiteScript code for a Suitelet that retrieves the
mainAddress
subrecord:
Copy code
javascript
/**
 * Suitelet
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
define(['N/record'], function(record) {
    function onRequest(context) {
        if (context.request.method === 'GET') {
            var locationId = context.request.parameters.id;
            var locationRec = record.load({
                type: record.Type.LOCATION,
                id: locationId
            });
            var mainAddressSubrecord = locationRec.getSubrecord({
                fieldId: 'mainaddress'
            });
            context.response.write(JSON.stringify(mainAddressSubrecord));
        }
    }
    return {
        onRequest: onRequest
    };
});
Remember to replace
{id}
with the actual ID of the location record you want to retrieve. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.837881804
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.820964813
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.804656923
Please provide your feedback on this answer.