2

I have a custom lwc development that gets a configuration object from the backend via @wire decorator that is cutting off one of the response properties.

{
  "cascadeMode": true,
  "frame": "current frame",
  "label": "OpenAI",
  "mappings": {
    "standard": {
      "method": "POST",
      "requestJSON": "{\r\n  \"model\": \"model\",\r\n  \"messages\": \"lwc_messages#_append[{'content':'lwc_content','role':'user'}#_atfirst_{'content':'lwc_frame','role':'system'}]\",\r\n  \"temperature\": 1,\r\n  \"top_p\": 1,\r\n  \"n\": 1,\r\n  \"stream\": false,\r\n  \"max_tokens\": 250,\r\n  \"pr",
      "type": "standard"
    }
  }
}

But my requestJSON property is way longer and looks like this:

{
    "model": "model",
    "messages": "lwc_messages@_append[{'content':'lwc_content','role':'user'}@_atfirst_{'content':'lwc_frame','role':'system'}]",
    "temperature": 1,
    "top_p": 1,
    "n": 1,
    "stream": false,
    "max_tokens": 250,
    "presence_penalty": 0,
    "frequency_penalty": 0
}

I've tried doing my backend call from the connectedCallback instead of using a @wire but no luck.

Is there something I'm missing here?

Regards,

4
  • Please edit to add the code snippet showing how this response gets populated. We have APIs that return far more data than this, so it's not a fundamental limitation.
    – Phil W
    Commented Feb 15 at 14:39
  • @PhilW I'm just adding the value (which is stored on a LongTextArea field in a CustomMetadata record) to an @AuraEnabled string property
    – molinet
    Commented Feb 15 at 14:42
  • 2
    OK, so I'm guessing you are getting the LongTextArea field value from a Custom Metadata Type record after getting that record through getInstance. Take a look at the documentation; to get more than the first 255 characters, you have to explicitly query (SOQL) the CMT record.
    – Phil W
    Commented Feb 15 at 16:10
  • @PhilW, this is a brilliant idea! I think you should post this as an answer for later readers, even if the OP seems to have lost interest. Commented Feb 26 at 22:28

1 Answer 1

5

I'm guessing you are getting the LongTextArea field value from a Custom Metadata Type record after getting that record through getInstance. Take a look at the documentation; to get more than the first 255 characters, you have to explicitly query (SOQL) the CMT record.

Our approach is to use getInstance and only follow this using an SOQL query if the returned long text area field value is 255 characters long.

There is a chance that the full value is exactly 255 characters long and in this case the query is unnecessary, but most of the time the values are either less than 255 in length (so no query) or more than 255 (so must be queried to get the whole value).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .