Browse Source

feat: add ISBLANK and ISNOTBLANK formula support

pull/9678/head
Pranav C 1 month ago
parent
commit
50d3f1ba94
  1. 30
      packages/noco-docs/docs/070.fields/040.field-types/060.formula/030.string-functions.md
  2. 30
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  3. 21
      packages/nocodb/src/db/functionMappings/commonFns.ts

30
packages/noco-docs/docs/070.fields/040.field-types/060.formula/030.string-functions.md

@ -237,6 +237,36 @@ URLENCODE(text)
=> 'https://example.com/q?param=Hello%2C%20world'
```
## ISBLANK
The ISBLANK function checks if the input string is empty or null and returns a boolean value.
#### Syntax
```plaintext
ISBLANK(text)
```
#### Sample
```plaintext
ISBLANK('') => true
ISBLANK('Hello') => false
```
## ISNONBLANK
The ISNONBLANK function checks if the input string is not empty or null and returns a boolean value.
#### Syntax
```plaintext
ISNONBLANK(text)
```
#### Sample
```plaintext
ISNONBLANK('') => false
ISNONBLANK('Hello') => true
```
## Related Articles
- [Numeric and Logical Operators](015.operators.md)

30
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -961,6 +961,36 @@ export const formulas: Record<string, FormulaMeta> = {
examples: ['MID("NocoDB", 3, 2) => "co"', 'MID({column1}, 3, 2)'],
returnType: FormulaDataTypes.STRING,
},
ISBLANK: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#isblank',
validation: {
args: {
rqd: 1,
type: [FormulaDataTypes.UNKNOWN],
},
},
description: 'Check if the input parameter is blank.',
syntax: 'ISBLANK(value)',
examples: ['ISBLANK({column1}) => false', 'ISBLANK("") => true'],
returnType: FormulaDataTypes.BOOLEAN,
},
ISNOTBLANK: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#isnotblank',
validation: {
args: {
rqd: 1,
type: [FormulaDataTypes.UNKNOWN],
},
},
description: 'Check if the input parameter is not blank.',
syntax: 'ISNOTBLANK(value)',
examples: ['ISNOTBLANK({column1}) => true', 'ISNOTBLANK("") => false'],
returnType: FormulaDataTypes.BOOLEAN,
},
IF: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#if',

21
packages/nocodb/src/db/functionMappings/commonFns.ts

@ -354,10 +354,18 @@ export default {
},
ISBLANK: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
const { builder: stringValueBuilder } = await fn({
type: 'CallExpression',
arguments: [pt.arguments[0]],
callee: {
type: 'Identifier',
name: 'STRING',
},
});
return {
builder: knex.raw(
`(${valueBuilder} IS NULL OR ${valueBuilder} = '')${colAlias}`,
`(${valueBuilder} IS NULL OR ${stringValueBuilder} = '')${colAlias}`,
),
};
},
@ -370,10 +378,17 @@ export default {
},
ISNOTBLANK: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
const { builder: stringValueBuilder } = await fn({
type: 'CallExpression',
arguments: [pt.arguments[0]],
callee: {
type: 'Identifier',
name: 'STRING',
},
});
return {
builder: knex.raw(
`(${valueBuilder} IS NOT NULL AND ${valueBuilder} != '')${colAlias}`,
`(${valueBuilder} IS NOT NULL AND ${stringValueBuilder} != '')${colAlias}`,
),
};
},

Loading…
Cancel
Save