Saving user input values in cdts from the editable grid

Certified Lead Developer

Hi,

I have editable grid having two columns one is readonly field for showing label and in the second column the user will enter the data. The data for this columns is getting from a local variable . The user can delete the rows and he add row upto 5 rows.

Now I have a cdt with fields like r1, r2, r3, r4, r5. Now I want to map the data entered by the user to cdt.

  Discussion posts and replies are publicly visible

Parents
  • You can just a!save() into the CDT with the local! values like below:

    a!save(ri!CDT.field, index(local!data, "fieldName", null)) <-- you may need an additional level of indexing if the data is nested and/or use type casting if the data types would differ

    You could also build an expression rule, that would be applied over using apply(), to construct the data into the given CDT and save it all in one shot (assuming this is when they submit the form, in a 'saveInto', use the examples below:

    --Rule being used/referenced--
    a!save(
    ri!cdtName,
    apply(
    rule!AppName_buildCDTName(_),
    local!varName /* <---This is assuming you're saving all the user's entries into a single variable */
    )

    --Within rule!AppName_buildCDTName--
    'type!{namespace}CDTName'(
    r1:index(ri!varName, "fieldName", null),
    r2:index(ri!varName, "fieldName", null),
    r3:index(ri!varName, "fieldName", null),
    r4:index(ri!varName, "fieldName", null),
    r5:index(ri!varName, "fieldName", null)
    )

    Note: Don't forget null checks on the a!save()

    You may also have to do some tinkering with the above code, but the options above should generally give you what you want. If you want a more precise answer, please provide the data structure of your local variable after the user has saved X entries.

Reply
  • You can just a!save() into the CDT with the local! values like below:

    a!save(ri!CDT.field, index(local!data, "fieldName", null)) <-- you may need an additional level of indexing if the data is nested and/or use type casting if the data types would differ

    You could also build an expression rule, that would be applied over using apply(), to construct the data into the given CDT and save it all in one shot (assuming this is when they submit the form, in a 'saveInto', use the examples below:

    --Rule being used/referenced--
    a!save(
    ri!cdtName,
    apply(
    rule!AppName_buildCDTName(_),
    local!varName /* <---This is assuming you're saving all the user's entries into a single variable */
    )

    --Within rule!AppName_buildCDTName--
    'type!{namespace}CDTName'(
    r1:index(ri!varName, "fieldName", null),
    r2:index(ri!varName, "fieldName", null),
    r3:index(ri!varName, "fieldName", null),
    r4:index(ri!varName, "fieldName", null),
    r5:index(ri!varName, "fieldName", null)
    )

    Note: Don't forget null checks on the a!save()

    You may also have to do some tinkering with the above code, but the options above should generally give you what you want. If you want a more precise answer, please provide the data structure of your local variable after the user has saved X entries.

Children