valueConstraint and LimitedValues doesn't seem to work

I have a custom table where we stage HR-data before syncing to Person. 

There's also a custom angular module where you can create and edit new external identities. 

On column has a a defined list of values 0,1,2,3. 

I want to be able to limit what certain users see in the Webportal when they create a new external identities. 

But it doesn't seem to work, I can se that valueConstraint.LimitedValues are set correctly, but all values are still showing in the dropdown list. 

Am I missing something, or is this not supported for imx-cdr-editor?

According to the documentation: 

Custom valueConstraint - if it is set it will be used instead of column.GetMetadata().valueConstraint

  private createCdrList(columnNames: string[], entity: IEntity): (ColumnDependentReference | undefined)[] {  
    let cdrList: (ColumnDependentReference | undefined)[] = [];
    cdrList = this.cdrFactoryService.buildCdrFromColumnList(entity, columnNames, false);

    cdrList.map((field) => {
      // Set minimum length for EmployeeID
      if (field?.column.ColumnName === 'CCC_EmployeeID') {
        field.minLength = 12;
      }
      // Limit CCC_EmployeeType to allowed values
      if (field?.column.ColumnName === 'CCC_EmployeeType') {
        const allowed = this.allowedEmployeeTypes;
        const limitedValues = field.column.GetMetadata().GetLimitedValues();
        if (limitedValues) {
          field.valueConstraint = {
            ...field.valueConstraint,
            LimitedValues: limitedValues.filter(v => allowed.includes(String(v.Value)))
          };

        }
      }
    })
    return cdrList;
  }

Parents
  • Same issue here: had a quick try to limit the default 'Gender' limitedValues on the profile page.

    Maybe   can confirm or correct the code ;-)

    v9.3:
    imxweb\projects\qer\src\lib\profile\profile.component.ts

       this.cdrList = (this.columns ?? []).map((columnName) => {
            let column = this.selectedIdentity.GetColumn(columnName);
            if (column.ColumnName == 'Gender') {
              return {
                column,
                isReadOnly: () => !column.GetMetadata().CanEdit(),
                hint: this.hints[columnName],
                valueConstraint: {
                  LimitedValues: [
                    {
                      Value: 1,
                      Description: '1 - male',
                    },
                    {
                      Value: 2,
                      Description: '2 - female',
                    },
                  ],
                },
              };
            } else {
              return {
                column,
                isReadOnly: () => !column.GetMetadata().CanEdit(),
                hint: this.hints[columnName],
              };
            }
          });


  • Hi,

    Hi, I do confirm Slight smile

    When the cdr logic renders the component it will read the values from the database, ignoring the custom LimitedValues definition. I guess you'll need to add an auxliary formcontrol with your data and eventually fill the real column with your choice.

  •  I've seen the related issue you've created on the github page. In the Description you state "According to the documentation: Custom .valueConstraint if set it will be used instead of column.GetMetadata().valueConstraint" ... You mean real documentation or the readme files? If the former, please, please, share Sweat smile

  •    Sorry there's no secret documentation Sweat smile it should have read comment from HTML application

    qbm\src\lib\cdr\column-dependent-reference.interface.ts

      /**
       * Custom valueConstraint - if it is set it will be used instead of column.GetMetadata().valueConstraint
       */
      valueConstraint?: ValueConstraint;
    

  • Joy thanks!! 

    I'm suscribed to the Github, I had news about the issue , yes. I guess we could dig into the code and find a solution but when it comes to "native" libraries I like to leave them untouched.

  • Hello all,

    Yes indeed this does not works as intended. Or at least the code is misleading here. There is a workaround here. It is not a beautiful solution but it does get the job done till this gets fixed.

    This acts as a hardcode filter, so it can lead to potential errors down the line. I tried to do this via Administration portal with Configuration keys but  no luck so far.

    Workaround:

    We have 2 classes to look into imxweb\projects\qbm\src\lib\cdr\entity-column-container.ts and imxweb\projects\qbm\src\lib\cdr\limited-values-container.ts.

    Add the following code:

    inside file imxweb\projects\qbm\src\lib\cdr\entity-column-container.ts

    // OOTB method we add our custom block
     public init(cdr: ColumnDependentReference): void {
        this.cdr = cdr;
    
        this.limitedValuesContainer = new LimitedValuesContainer(cdr.column.GetMetadata());
        // CCC_custom block starts gere
        if (this.cdr.column.ColumnName === '<NAME OF COLUMN>' && this.cdr.valueConstraint?.LimitedValues?.length > 0) {
          this.limitedValuesContainer.CCC_removeMatchingLimitedValues([
            {
              Value: '0', // this is an example. find your desired value in DB. Must be string.
            },
            {
              Value: '4', // this is an example. find your desired value in DB. Must be string.
            },
          ]);
        }
      }

    inside file imxweb\projects\qbm\src\lib\cdr\limited-values-container.ts

    // declare this value 
    // CCC_custom
      private filteredValues: ReadonlyArray<LimitedValueData>; // Store the filtered values
      
    // inside constructor we call our values
     constructor(private metadata: IValueMetadata) {
        // CCC_custom
        this.filteredValues = this.metadata ? this.metadata.GetLimitedValues() : []; // Initialize with all values
      }
    
    // we add our custom method here 
    /**
       * Removes matching limited values based on the provided object (compares both Value and Description).
       * @param obj The object to compare and remove from the limited values.
       * @returns The new filtered array of limited values without the matching items.
       */
      public CCC_removeMatchingLimitedValues(objArray: LimitedValueData[]): void {
        if (!this.filteredValues || !objArray || objArray.length === 0) return;
    
        // Filter out all matching values
        this.filteredValues = this.filteredValues.filter((value) => !objArray.some((obj) => obj.Value === value.Value));
      }

    Hope this helps abit with your debugging.

    Have a nice day,

    Zan

  •  Thank you for this really appreciated!

Reply Children
No Data