https://netsuiteprofessionals.com logo
#sdf
Title
# sdf
d

darrenhillconsulting

04/26/2022, 1:59 AM
I have a SuiteApp that has custom records with fields that reference the SUBSIDIARY record. Deploying this SuiteApp to a NON OneWorld account, those fields get DROPPED. All fields that reference the SUBSIDIARY record get dropped. Is there a way around that? (I know a non OneWorld account still has a subsidiary === 1)
m

Matt Bernstein

04/26/2022, 3:00 AM
Nope! the record is completely fine, but i've seen issues in searches and then the form breaks as well as a custom role with the subsidiary permission. I created a support ticket and it's considered an enhancement. The way I got around the form is to comment out the subsidiary field on the xml form file and then I have a before load script to add a mock subsidiary field and hide the original and then before submit to update the value of the original field with the mocked field value. Happy to share the code with you if you want!
d

darrenhillconsulting

04/26/2022, 4:58 PM
@Matt Bernstein, would love to see that. Thanks!
m

Matt Bernstein

04/27/2022, 1:27 PM
UE
Copy code
//before load
commonController.mockSubsidiaryBeforeLoad(scriptContext, {
    subsidiaryFieldId: "<<ORIGINAL SUBSIDIARY FIELD ID>>",
    nextFieldId: "<<FIELD ID OF FIELD THAT WILL COME AFTER THE MOCKED FIELD>>",
});

//before submit
commonController.mockSubsidiaryBeforeSubmit(scriptContext, {
    fieldId: "<<ORIGINAL SUBSIDIARY FIELD ID>>",
});
common controller file
Copy code
md.mockSubsidiaryBeforeLoad = (scriptContext, options) => {
    if (runtime.executionContext === "USERINTERFACE") {
        let form = scriptContext.form;
        const subsidiaryField = form.getField({
            id: options.subsidiaryFieldId,
        });
        if (subsidiaryField) {
            const mockField = form.addField(
                {
                    id: "custpage_sub_mock"
                    type: subsidiaryField.type,
                    isMandatory: subsidiaryField.isMandatory,
                    label: subsidiaryField.label,
                    source: "subsidiary",
                }
            );
            if (subsidiaryField.defaultValue) {
                form.updateDefaultValues({
                    custpage_subsidiary: subsidiaryField.defaultValue,
                });
            }
            mockField.setHelpText({
                help: "<<INSERT ANY HELP TEXT>>",
            });
            form.insertField({
                field: mockField,
                nextfield: options.nextFieldId,
            });

            md.updateFieldDisplayTypeServer({form, fieldId: options.subsidiaryFieldId, displayType: "hidden"});
        }
    }
};
md.mockSubsidiaryBeforeSubmit = (scriptContext, options) => {
        if (runtime.executionContext === "USERINTERFACE") {
            let newRecord = scriptContext.newRecord;

            const isChanged = md.didFieldChange(scriptContext, {
                fieldId: options.fieldId,
                mockFieldId: jsonController.MOCK_SUBSIDIARY.ID,
            });
            if (isChanged === true) {
                newRecord.setValue({fieldId: options.fieldId, value: newRecord.getValue({fieldId: jsonController.MOCK_SUBSIDIARY.ID})});
            }
        }
    };
    /**
     * @function didFieldChange
     * @param {Object} scriptContext
     * @param {Object} options
     * @param {String} options.fieldId
     * @param {String} options.mockFieldId
     * @returns {boolean}
     */
    md.didFieldChange = (scriptContext, options ) => {
        const oldRecord = scriptContext.oldRecord;
        const newRecord = scriptContext.newRecord;
        if (!oldRecord || !newRecord) return true;
        if (scriptContext.type === "xedit") {
            const fields = JSON.parse(JSON.stringify(newRecord)).fields;
            if (fields && Object.keys(fields).length > 0) {
                if (!fields.hasOwnProperty(options.fieldId)) {
                    return false;
                }
            }
            else {
                return false;
            }
        }

        let newValue = newRecord.getValue(options.fieldId);
        let oldValue = oldRecord.getValue(options.mockFieldId || options.fieldId);
        if (newValue && typeof newValue === "object") {
            newValue = md.getDateTimeString(newValue);
        }
        if (oldValue && typeof oldValue === "object") {
            oldValue = md.getDateTimeString(oldValue);
        }
        return oldValue !== newValue;
    };
md.updateFieldDisplayTypeServer = (options) => {
        const form = options.form;
        if (!options.fieldId) return;
        let field = form.getField(options.fieldId);
        if (field) {
            field.updateDisplayType({displayType: options.displayType});
        }
    };
    md.getDateTimeString = (d) => {
        if (d && typeof d === "object") {
            return format.format({type: format.Type.DATETIME, value: d});
        }
        return d;
    };
That should be all the code snippets. It's a before load and before submit function. the before load hides the original subsidiary field and then creates a new one being inserted before the passed in field id. before submit checks to see if the mock field changed and if so, set the original subsidiary field to the mocked field value