- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 07:29 AM
Hi all,
In trying to enhance the functionality of a widget in the service portal, I have come across what I fee is an error. I am using the method "getElementById()" on an element that I know for sure exists, and it is coming back null.
Is there a work around to this or and alternative method I should/could use?
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 07:46 AM
I just realized I named the variable incorrectly in the ng-if lol. That's probably the issue
This is what I had:
<div id="ifTrue" ng-if="data.userFormApproval">
...
<div id="ifFalse"ng-if="!data.userFormApproval">
But you're setting the true/false to this variable in your server script: data.userFormApprovalArray.
So it should be:
<div id="ifTrue" ng-if="data.userFormApprovalArray">
...
<div id="ifFalse"ng-if="!data.userFormApprovalArray">
Let me know if that works! I edited my original post with that change.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 05:58 AM
Hi Justin,
Sorry for the late reply!
Instead of doing it that way, I would recommend using in the userFormApproval variable in data object and leveraging ng-if on the two div's (the ifTrue ifFalse ones). Try to take advantage of angular where possible. Ng-if will hide/show the content based on the condition you give.
This is going to be untested, but here is what I'd suggest.
HTML:
<div id="ifTrue" ng-if="data.userFormApprovalArray">
<div ng-if="options.portal && approval.state == 'requested'" class="col-xs-6">
<button name="reject" class="btn btn-danger btn-block" ng-click="reject(approval.sys_id);">${Do Not Need}</button>
</div>
<div ng-if="options.portal && approval.state == 'requested'" class="col-xs-6">
<button name="approve" class="btn btn-success btn-block" ng-click="approve(approval.sys_id);">${Completed}</button>
</div>
</div>
<div id="ifFalse"ng-if="!data.userFormApprovalArray">
<div ng-if="options.portal && approval.state == 'requested'" class="col-xs-6">
<button name="reject" class="btn btn-danger btn-block" ng-click="reject(approval.sys_id);">${Reject}</button>
</div>
<div ng-if="options.portal && approval.state == 'requested'" class="col-xs-6">
<button name="approve" class="btn btn-success btn-block" ng-click="approve(approval.sys_id);">${Approve}</button>
</div>
</div>
Client Controller:
//Don't need anything here
Server Script:
var userFormApproval = false;
if(j.instructions.indexOf('User Form') !== -1){
userFormApproval = true;
}else{
userFormApproval = false;
}
data.userFormApprvalArray = [];
data.userFormApprovalArray = userFormApproval;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 08:46 AM
Hi Justin,
Any updates here? Did the code I posted solve the issue?
If so, can you please mark my answer as correct, otherwise I'm happy to continue to help
Thanks,
Josh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 04:56 AM
Hi, sorry for the delay!
I tried your code and, while the value was coming through as true it still showed the incorrect set of buttons. could it be the buttons?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 07:46 AM
I just realized I named the variable incorrectly in the ng-if lol. That's probably the issue
This is what I had:
<div id="ifTrue" ng-if="data.userFormApproval">
...
<div id="ifFalse"ng-if="!data.userFormApproval">
But you're setting the true/false to this variable in your server script: data.userFormApprovalArray.
So it should be:
<div id="ifTrue" ng-if="data.userFormApprovalArray">
...
<div id="ifFalse"ng-if="!data.userFormApprovalArray">
Let me know if that works! I edited my original post with that change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 08:57 AM
That worked!
Thank you so much!