Page 1 of 1

Default value on subform objects when form is saved

Posted: Mon May 20, 2024 7:16 pm
by Costa
Good evening everyone,

forgive the beginner's question but I searched and didn't find what I need.

I have a form with a subform and I need that when I insert the form fields and save it, the subform first record is also saved and, if no values has been inserted in the subform record, i need to insert a default value in a lookup object and in a input object (number) of the subform.

Thanks for any tips
Costa

Re: Default value on subform objects when form is saved

Posted: Tue May 21, 2024 9:30 am
by kev1n
Add a function nuBeforeSave() in your form's Custom Code.

Example:

Code: Select all

function nuBeforeSave() {

    const subformId = 'mysubform'; // subform object id
    const lookupObjectId = 'mylookup'; //  Id of your lookup object
    const lookupValue = '6505159c7272cf6'; // Primary key of lookup value to be set

    const firstLookupObj = $('#' + subformId + '000' + lookupObjectId);

    if (firstLookupObj.val() === '') {
        firstLookupObj.val(lookupValue).addClass('nuEdited');
    }

    const numberObjectId = 'myinput'; //  Id of your input/number object
    const numberValue = '123'; // number value to be set

    const firstNumberObj = $('#' + subformId + '000' + numberObjectId);

    if (firstNumberObj.val() === '') {
        firstNumberObj.nuSetValue(numberValue);
    }

    $('#' + subformId + '000' + 'nuDelete').nuSetValue(false);

    return true;

}

Re: Default value on subform objects when form is saved

Posted: Wed May 22, 2024 5:18 pm
by Costa
Thanks Kev1n,

always the top!

later i will try and i will be back to you

Costa

Re: Default value on subform objects when form is saved

Posted: Wed May 22, 2024 5:23 pm
by Costa
Perfect!

It works like a charm at the first shot.

Thanks Kev1n!!

Costa