show/hide widget with condition

Brook3
Giga Expert

Hello Experts,

I have no idea.. why my code is not working.

I want to display the widget when the created condition is met.

 

html

<div class="row" ng-show="data.visible">
<div class="panel-group">test content
</div>
</div>

server

(function() {
data.visible = true;
var grrr = new GlideRecord("sn_hr_core_case_talent_management");
grrr.addQuery("opened_by", gs.getUserName());
grrr.addEncodedQuery('hr_service=f3d54c07db067700f75893c8f4961917^u_expected_dateISNOTEMPTY');
grrr.query();
if (grrr.next()) {
data.visible = false;
}

})();

Thank you in advance!

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

Please use: ng-if instead of ng-show.

Here's a post to help give more information: https://community.servicenow.com/community?id=community_question&sys_id=ab4e8780db692f04d6a102d5ca96...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I just wanted to check-in on this and see if this has been resolved.

If my reply above helped guide you correctly, please mark as Helpful & Correct.

Thank you!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Willem
Giga Sage
Giga Sage

Hi Brook,

 

Can you elaborate what you mean with "my code is not working". What are you expecting and what is happening? How did you test it?

Also not sure what you mean with "I want to display the widget when the created condition is met". What is the condition? If you find the record you want to show it? Or if you find a record you do not want to show it?

 

If the first is the case you can use ng-hide:

<div class="row" ng-hide="data.visible">
<div class="panel-group">test content
</div>
</div>

 

Server script can stay the same.

Subhanand
Tera Guru

Hi brook,

Since opened by is reference field user gs.getUserID()

In the GlideRecord instead of gs.getUserName() use gs.getUserID()

 data.visible = true;
 var grrr = new GlideRecord("sn_hr_core_case_talent_management");
 grrr.addQuery("opened_by", gs.getUserID());
 grrr.addEncodedQuery('hr_service=f3d54c07db067700f75893c8f4961917^u_expected_dateISNOTEMPTY');
 grrr.query();
 if (grrr.next()) {
 data.visible = false;
} 

since gs.getUserName()  returns "name" gs.getUserID() returns Sysid