Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Refreshing image of button

Posted on by 40

Hi everybody,

Today I'm facing a little issue.

In a form, I have a simple Menu Item Button whith an icon from Embedded ressources and text defined.

In active method of the main datasource, I change the text and the icon based on value. This works well.

In addition, when I click on the button itself, the text and icon have to change too. This works too except the first time I click the button after opening the form, the text change well but the icon dont.

I tried lock/unlock, lockWindowUpdate and even redraw methods on form, but it doesn't work. I tried to execute the sequence in debugger but it doesn't help. 

Again, the problem occurs only the first time I click on, if I click multiple time, the icon switch well.

Here's my code :

void clicked()
{
    super();
    element.DLZmanageLockedPurchSalesInventButton();
}

public void DLZmanageLockedPurchSalesInventButton()
{
    InventItemInventSetup           inventItemInventSetup;
    InventItemPurchSetup            inventItemPurchSetup;
    InventItemSalesSetup            inventItemSalesSetup;
    
    #define.inventDimIdBlank("AllBlank")
    #define.imgLock("12102")
    #define.imgUnlock("12103")


    select firstOnly inventItemPurchSetup
    where inventItemPurchSetup.ItemId       == InventTable.ItemId   &&
          inventItemPurchSetup.InventDimId  == #inventDimIdBlank;

    if(inventItemPurchSetup.RecId)
    {
        if (inventItemPurchSetup.Stopped)
        {
            DLZItemLockPurch.text("@DLZ1433");
            DLZItemLockPurch.normalImage(#imgUnlock);
        }
        else
        {
            DLZItemLockPurch.text("@DLZ1434");
            DLZItemLockPurch.normalImage(#imgLock);
        }
    }

    select firstOnly inventItemSalesSetup
    where inventItemSalesSetup.ItemId       == InventTable.ItemId   &&
          inventItemSalesSetup.InventDimId  == #inventDimIdBlank;

    if(inventItemSalesSetup.RecId)
    {
        if (inventItemSalesSetup.Stopped)
        {
            DLZItemLockSales.text("@DLZ1435");
            DLZItemLockSales.normalImage(#imgUnlock);
        }
        else
        {
            DLZItemLockSales.text("@DLZ1436");
            DLZItemLockSales.normalImage(#imgLock);
        }
    }

    select firstOnly inventItemInventSetup
    where inventItemInventSetup.ItemId       == InventTable.ItemId   &&
          inventItemInventSetup.InventDimId  == #inventDimIdBlank;

    if(inventItemInventSetup.RecId)
    {
        if (inventItemInventSetup.Stopped)
        {
            DLZItemLockInvent.text("@DLZ1437");
            DLZItemLockInvent.normalImage(#imgUnlock);
        }
        else
        {
            DLZItemLockInvent.text("@DLZ1438");
            DLZItemLockInvent.normalImage(#imgLock);
        }
    }
}

  • stekbi Profile Picture
    stekbi 40 on at
    RE: Refreshing image of button

    Hi Sergei and thank you for answering.

    As I said earlier, I already tried this solution without any result.

  • Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,089 on at
    RE: Refreshing image of button

    Hi Stekbi,

    You can try also to force form redraw with element.redraw() method.

  • Verified answer
    stekbi Profile Picture
    stekbi 40 on at
    RE: Refreshing image of button

    MMm okay, I desperately tried something :

    void clicked()
    {
        #define.imgLock("12102")
        #define.imgUnlock("12103")
    
        this.normalImage(#imgLock);
        this.normalImage(#imgLock);
    
        super();
        //element.DLZmanageLockedPurchSalesInventButton();
    }

    And it works.... I'm not satisfied with this.

    My ego and curiosity as young developper cannot accept this, I need to understand.

  • stekbi Profile Picture
    stekbi 40 on at
    RE: Refreshing image of button

    The original image of button is 12103. I tested the code you suggest and still the same problem. First click -> nothing, second click change image.

    In debugger, the property change well from first click.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Refreshing image of button

    Not sure what these two images are, but to me it seems you still have too much logic to really test it. I don't know what is the original image in the button when the form is opened, and what is value of "i" when the form is opened, so there's still too many unknown variables for me.

    My assumption is that your if-else conditions are not working as you expect.

    So please try this:

    void clicked()
    {
        #define.imgLock("12102")
        this.normalImage(#imgLock);
    
        super();
    
    }

    It should change the button image to #imgLock when the button is clicked (one time).

    Does it work?

  • stekbi Profile Picture
    stekbi 40 on at
    RE: Refreshing image of button

    Thank you for helping.

    I followed your advice by commenting all code related to this button (active method of DS, etc) and simplified the logic for testing purpose. Here's my simplified logic :

    void clicked()
    {
        #define.imgLock("12102")
        #define.imgUnlock("12103")
        
        i  ;
        if (i mod 2 == 0)
        {
            this.normalImage(#imgUnlock);
        }
        else
        {
            this.normalImage(#imgLock);
        }
        
        super();
        //element.DLZmanageLockedPurchSalesInventButton();
    }

    My var "i" is declared in classDeclaration of form.

    The problem remain the same. On first click, nothing happen, but on next everythink is going well. I debuged and the properties take the good value but the icon dont switch.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Refreshing image of button

    Did you debug it? I recommend removing all business logic for now and concentrate on changing the image of the button when it's clicked. This way you can investigate only the part that is important for changing the image, and be sure that nothing else is causing unexpected results.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans