diff --git a/packages/noco-docs/docs/070.fields/040.field-types/060.formula/030.string-functions.md b/packages/noco-docs/docs/070.fields/040.field-types/060.formula/030.string-functions.md index 85e00d4aad..b488d292ee 100644 --- a/packages/noco-docs/docs/070.fields/040.field-types/060.formula/030.string-functions.md +++ b/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) diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index e5c2b4ff1a..157df577aa 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -961,6 +961,36 @@ export const formulas: Record = { 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', diff --git a/packages/nocodb/src/db/functionMappings/commonFns.ts b/packages/nocodb/src/db/functionMappings/commonFns.ts index 79b285acec..2c534e22c9 100644 --- a/packages/nocodb/src/db/functionMappings/commonFns.ts +++ b/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}`, ), }; },