Set value on one of the field in a Sub-List

HI, Is it possible to pre-set a value when every time user click the ‘Add’ button on a Sub-List?

I created a SubList as follow:

What I want to do is when user click Add: image

I would like to set a value(e.g. current user name) on this field.

Is it possible on YeeFlow?

Thank you!

Steve,

Sorry this cannot be done by configuration. An idea is use a custom button to trigger an action. Action step execute a script to add new row to list with default value.

import { LIST_ROW_DELETE, MODULE_COMMON } from "./constants";

export class CodeInApplication implements CodeInComp {
    execute(context: CodeInContext, fieldsValues: any) {
        return new Promise((resolve, reject) => {
            
            const params = context.params;
            const common = context.modules[MODULE_COMMON];
            const fieldId = params["varId"];
            if (!fieldId) {
                alert("Please configure input parameter: varId");
                resolve(false);
            }
            const username = context.getFieldValue("field_name"); //variable store the name of current user

            let list = fieldsValues[fieldId] || [];

            list.push({ "field_1": username});

            context.setFieldValue(fieldId, [...list]); //form a new object otherwise the list will not be refreshed.

            resolve(true);
        });
    }

    requiredFields(params) {
        return [params["varId"]];
    }

    requiredModules() {
        return [];
    }

    description() {
        return "Add row of a list";
    }

    inputParameters() {
        return [{
            id: "varId",
            type: "string",
            desc: "Varaible ID of the list"
        }] as InputParameter[];
    }
}

Regards,
Frank

1 Like

hi frank, seems the script can’t get the SubList information correctly?

here’s my code:

import { MODULE_COMMON, MODULE_REQUEST } from "./constants";

export class CodeInApplication implements CodeInComp {
  async execute(context: CodeInContext, fieldsValues: any) {
    return new Promise((resolve, reject) => {
      const params = context.params;
      console.log("params: ", params);

      const common = context.modules[MODULE_COMMON];

      const fieldId = params["message_box_id"];
      console.log("fieldId: ", fieldId);

      if (!fieldId) {
        alert("Please configure input parameter: varId");
        resolve(false);
      }

      // const username = context.getFieldValue("field_name"); //variable store the name of current user

      // let list = fieldsValues[fieldId] || [];
      // console.log('Lits: ', list);

      // list.push({ field_1: 'ha' });

      // context.setFieldValue(fieldId, [...list]); //form a new object otherwise the list will not be refreshed.

      resolve(true);
    });
  }

  requiredFields(params) {
    return [params["message_box_id"]];
  }

  requiredModules() {
    return [];
  }

  description() {
    return "Add row of a list";
  }

  inputParameters() {
    return [
      {
        id: "message_box_id",
        type: "string",
        desc: "Varaible ID of the list",
      },
    ] as InputParameter[];
  }
}

Thank you

Hi Steve,

In your case, message_box_id should be the param value set for the custom code.

image

Hi frank, I am using “Action” here. I can’t find where to put this Input parameters. Am I doing this action incorrect?

The input variable is defined at here

inputParameters() {
    return [
      {
        id: "message_box_id",
        type: "string",
        desc: "Varaible ID of the list",
      },
    ] as InputParameter[];
  }

It may be a litter bit delay in update, please save the step and then reopen the it to have a check.