Show Image if field value equals…

ByRob Peledie

Show Image if field value equals…

Before I start, a massive shout out to Charles Osei .As part of the TDG team, we had a discussion, and his solution totally solved the requirement I had. Also another great example of how a collaborative group can work.

Had a requirement recently to show something a little more visual on a record form if a tick box was chosen…… something that would immediately show the user the status or conditions on a record.
In this example, were going to show Icons for Key Accounts and Sensitive Accounts at the top of the form if the corresponding fields are ticked.

Firstly, find your icons. For me I decided on a key for the Key Accounts, and an exclamation for the sensitive accounts, but I also added some text:

These need to be added to Dynamics as Web Resources.

Next add a section on your account form (I added a 3 column one) and add the two new icon web resources to it. Make sure you untick the box “Visible by Default” for each web resource.

You also need to add your radio buttons on the form – in my case one for Key Account and One for Sensitive.

Once these are all on, save and publish.

Next create a new web resource of type Script (JScript).

//Shows/hides keyaccount img webresouce based on a tickbox two option field

function alertpic (executionContext) 
{
    var formContext = executionContext.getFormContext();
	
    var keyaccount = formContext.getAttribute("uob_keyaccount").getValue();
	
    if (keyaccount === true) {
        formContext.getControl("WebResource_keyacc").setVisible(true);
    }
    else {
        formContext.getControl("WebResource_keyacc").setVisible(false);
    }
}

//Shows/hides sensacc img webresouce based on a tickbox two option field

function sensalert (executionContext) 
{
    var formContext = executionContext.getFormContext();
	
    var sensacc = formContext.getAttribute("uob_sensitiveaccount").getValue();
	
    if (sensacc === true) {
        formContext.getControl("WebResource_sensacc").setVisible(true);
    }
    else {
        formContext.getControl("WebResource_sensacc").setVisible(false);
    }
}

So the first variable sets the context (this will be passed as a parameter when you call the function).

The second variable is the tick box field.

Then depending on the value (True/False) it shows or hides the Icon.

Don’t forget to call the function from both Onload and Onchange (On the field)

The result:

About the author

Rob Peledie administrator

2 Comments so far

Dynamics V9 Show/Hide WebresourcesPosted on12:14 pm - Jan 21, 2019

[…] Robert Peledie also describes a very usable scenario this and in more detail over at his blog […]

Show Image if field value equals… – 365Knowledge – Dynamics365BlogsPosted on12:10 pm - Feb 13, 2019

[…] Show Image if field value equals… […]

Leave a Reply