Forum Discussion

apdidy's avatar
apdidy
Ideator I
2 years ago
Solved

How to disable delete relationship button based on parent item state?

I know this question has been asked multiple times and I have reviewed all the ones that had answers. None of them seemed to clearly lead me in the right direction. I feel what I'm trying to do is ...
  • apdidy's avatar
    2 years ago

    Here is my complete solution for disabling the delete button when the ECN is In Review status or after.

    Open the ECN Item and go to Relationships tab. For this example, I am changing the ECN Affected Item.

    Open the ECN Affected Item (Not the relationship)

    - Go to Client Style

    - Create a new Presentation Configuration (If already exists, just open the existing one)

    Create a new CommandBarSection.

    Open CommandBarSection created above.

    - Add the existing Command Bar Item: itemview.relationshipscommandbar.default.deleterow

    - Enter remaining fields per screen shot, except the Alternate. (we have to create this first)

    Copy method:  cui_ivrcb_deleterow_init and create a new method. Adjust the if statement as needed based on the LifeCycle States you want the button disabled for.

    let isDisabled = true;
    if (window.computeCorrectControlState) {
    isDisabled = !window.computeCorrectControlState('delete');

    let parentItemLifeCycleState = parent.thisItem.getProperty('state', null);

    if (parentItemLifeCycleState === 'In Review' || parentItemLifeCycleState === 'Checker'
    || parentItemLifeCycleState === 'Final Approval' || parentItemLifeCycleState === 'Released')
    {
    isDisabled = true;
    }

    }
    const tooltip = target.tooltip_template.replace(
    '{0}',
    options.relationshipItemTypeLabel
    );
    return {
    disabled: isDisabled,
    tooltip_template: tooltip
    };

    Open the Command Bar Item above (this will open the existing Command Bar Item)

    - Click the ... -> Create New Button

    - Fill in the fields as shown.

    The delete button should now be disabled when the ECN is not in New or In Work states. 

    - If you are not getting the results you expect, clear your Metadata cache.