Hiding widget on page based on specific field value

rdskn023ET
Tera Contributor

Hi,

Someone created a page for us using their custom widgets. I am looking to hide one of those widgets from the page when a specific field value is equal to false. I have created a T/F field in the project_status table. By default, this field will be equal to True, so that the widget will be shown. If the user deselects this option when creating their status report, the value would be set to False and I would like for the widget to be hidden when viewing the page for that specific status report. Basically, the page is a summary page for projects that gathers information from the status report, along with a lot of other information from variable tables. The dates for this page are pulled and linked to the status reports, so for each date, there should be a T/F value associated with it, at which point that would determine if the widget would be displayed. If anyone has any advice or done something similar, any assistance would be appreciated!

4 REPLIES 4

Tom Sienkiewicz
Mega Sage

Hi, not sure how your page is set up, but generally you would use the angular ng-if directive for that I think.

If the widget is embedded in the page's html, you can wrap the specific line in this ng-if statement, or if it is added using the page designer, you can probably wrap the entire html in it.

See an example here https://www.w3schools.com/angular/ng_ng-if.asp

You can see this in almost every OOTB portal widget so you might want to check out a few of them as well.

rdskn023ET
Tera Contributor

Thanks Tomasz. I am using the ng-if directive in in the HTML body portion of the page. However, the issue seems to be in the Server script portion of the widget. There is a script include that is referenced on the server script that is pulling the data. It seems that the issue is that the data is not coming back into the server script, as the ng-if seems to just be receiving an undefined value. Basically, it is setting the variable in the script include, looking for the value in the body html, but there needs to be something in the server script that is pulling that value in. Any thoughts?

 

Also, on a separate note, they are using the following code to pull in the planned cost variable from the status report but it seems to be spotty. It works sometimes and other times it is not pulling the correct value in. This value needs to be based on the date for which the status report was created. So for each status report that is created, it should display the correct planned cost value. Any thoughts?

			var oticActual = new GlideRecord('project_status');
		oticActual.addEncodedQuery("project=" + prj + "^date<=javascript:gs.dateGenerate('" + date + "','23:59:59')^as_on=javascript:gs.dateGenerate('" + date + "','23:59:59')^fieldname=work_cost");
		oticActual.setLimit(1);
		oticActual.query();
		var oticActualTotal = 0;
		while(oticActual.next()){
			oticActualTotal = oticActualTotal + Number(oticActual.work_cost);
			
		}

 

The first part is hard to answer without having access to all the widgets.

If you know which variable is used in the HTML ng-if part, see how that variable is used and populated in client controller or server script. There could be a problem with refreshing the model, with widget load timing, many other things. Typically, server script needs to set the data.your_variable for ng-if to handle it. If you are using events in client part or just calling server part from it, check if your response.data is assigned to $scope.data to refresh it.

Regarding your second question, it is also guessing, but perhaps you can log the values received from those dates in your encoded query, and see if they really match your "date" variable as expected. Perhaps there is an issue with some formatting here.

Other than that, perhaps there an issue with the data iteslf - e.g. you're grabbing the first record returned (setlimit) but what if there are more records returned? Why use while loop if you're just limiting to one record?

Thanks Tomasz. 

Regarding the second question, I thought the same thing and tried removing that previously, but what happens is that it then begins adding all the values together. For instance, if the value for date #1 is 100,000 and 50,000 for date #2 for the status reports, it will display 150,000 for the latest date rather than 100,000. I assume it is something with how they have coded the total value. I may need to play with that.