"Scanning" for fields in an App?

Heya folks! Brand new to Kintone development and working on a sample plugin to trim text-input fields, and I’m having some trouble with the config.js side of things.

What I’m looking to do is have the code read the app the plugin is attached to, and for every text/string-capable field, create a radio dial to control enabling or disabling the plugin’s trim effect on the field.

The closest I can find in the API documentation is getFormFields, which would let me name each of the fields individually, I suppose, something like

if(field === "text", "rich text", "text area", "number"{

  fieldTrimmer(field)

}

But that’s fairly clunky, and I noticed there was a “text category” in the API docs for those 4 fields.

Is there any way to sort what fields an app is using in a smoother manner than naming them individually?

Sorry if these are some basic stuff, but this is my first plugin, and tbh I’ve only recently started doing actual development work, so it’s not like I’m feeling super confident on the pure JS side either ha ha ha. I appreciate any help anyone can offer.

Thanks so much!

Current update:

I am working off the kintone-samples/SAMPLE-Character-count-plug-in.

I’ve been working on using cases for each text field I’m going to trim, I’m just working now on turning the drop-down tables into radio dials, and replacing the count functions from the sample with onEvent input trimming.

I’m going to tackle the radio dial controls, I think, by referring to them in the desktop.js file for a if/else statement, something like

onEvent(record.create) or onEvent(record.update)

if (this.radio.value = "on") {
  function fieldtrimmer(input) {
    input = input.trim()
  }
} else {
  return input
}

Something along those lines, again, very new to kintone and dev in general, sorry this is so rough. Thanks for any input!

Hi @Christopher_Foster ,

I’m sorry, but I am a bit confused by your question.

I assume that on the plugin side, you want to retrieve the following on the form smoothly:

  • MULTI_LINE_TEXT: Text Area (“Text area” field)
  • RICH_TEXT: Rich text (“Rich text” field)
  • SINGLE_LINE_TEXT: Text, or Look-up* (“Text” field)
  • NUMBER: Number, or Look-up* (“Number” field)

Please correct me if I misunderstood, but you are inquiring because you have to set the field code to identify it as the above field, which would be too much work.

As you have mentioned, when checking the type of a field, it is possible to execute the Get Form fields API.

Also, extracting the target fields by checking the type is possible, as in the following process.

Example:

  • Target fields are stored in the “results” array.
  • Fields in a table are not included, so if a table is also applicable, processing for the table must also be added.
var body = {
  'app': kintone.app.getId()
};

kintone.api(kintone.api.url('/k/v1/app/form/fields', true), 'GET', body, function(resp) {

  var results = [];

  for(var code in resp.properties){
    var field = resp.properties[code];
    switch (field.type) {

       case 'MULTI_LINE_TEXT':
       case 'RICH_TEXT':
       case 'SINGLE_LINE_TEXT':
       case 'NUMBER':
         results.push(field);
         break;

       default :
           break;
    }
  }
  console.log(results);

}, function(error) {
  console.log(error);
});

After executing the above process in the developer tool’s console screen, I could extract only the target fields on my test app.
I don’t think you need to worry about the field code settings for the above process.

If there are any misunderstandings, I would like to ask for an elaboration on the following points:

But that’s fairly clunky, and I noticed there was a “text category” in the API docs for those 4 fields.

Is there any way to sort what fields an app is using in a smoother manner than naming them individually?

I hope this helps.