Question

Required Field with Conditions

Hello!

I`m trying to set up the requirement condition of a page field. Using this article as example: https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/platform-customization/freedom-ui/customize-page-fields/examples/set-up-the-requirement-condition-of-a-field

 

 

But I have no exp with JavaScript. So could u please help.

This part below not working properly :(

 

request: "crt.HandleViewModelAttributeChangeRequest",
        /* The custom implementation of the system request handler. */
        handler: async (request, next) => {
            /* Check the request status. */
            if (request.attributeName === 'PDS_AmountTest') {
                const newStatusId = 100000;
                const selectedStatus = await request.$context.PDS_AmountTest;
                const selectedStatusId = selectedStatus?.value;
                const isNewRequest = selectedStatusId === newStatusId;
              /* Check the request description. */
                if (isNewRequest) {
                    request.$context.enableAttributeValidator('AmountTest', 'required');
                } else {
                    request.$context.disableAttributeValidator('AmountTest', 'required');
                }
            }
            /* Call the next handler if it exists and return its result. */
            return next?.handle(request);
        }
    }
Like 0

Like

1 comments

Hello,
Based on the code alone it is hard to find the cause of the issue, debugging needs to be performed in such situations.

As for the general advice, make sure you are getting the correct parameter for request.attributeName. PDS_AmountTest is supposed to be a Code of the column you change. Also, the issue might be in this row:

const selectedStatusId = selectedStatus?.value;

The non-lookup attributes might not have a value, just 

const selectedStatusId = await request.$context.PDS_AmountTest;

might be enough.

Show all comments