[Eg-newdevs] get_tcn function scope

Terran McCanna tmccanna at georgialibraries.org
Thu Jun 17 13:11:51 EDT 2021


Okay, gang. I'm missing something and it's probably obvious to someone more
familiar with chained functions and scope, but I can't figure it out. After
trying a bunch of different approaches, this is the closest I've been able
to get. It's writing the correct value to the console log, but it is
displaying the *previous* value in the interface. Argh. See video demo of
the problem:

https://screencast-o-matic.com/watch/cr1bDNV16uo

**********

    $scope.local_overlay_target =
egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;
    if($scope.local_overlay_target) {
        var currTarget = $scope.local_overlay_target;
       * $scope.local_overlay_target_tcn = get_tcn(currTarget);*
    }
    $scope.mark_as_overlay_target = function() {
        var items = $scope.gridControls.selectedItems();
        if ($scope.local_overlay_target == items[0]['bibid']) {
            $scope.local_overlay_target = 0;
            $scope.local_overlay_target_tcn = 0;
        } else {
            $scope.local_overlay_target = items[0]['bibid'];
            var currTarget = items[0]['bibid'];
            *$scope.local_overlay_target_tcn = get_tcn(currTarget);*
        }

egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.local_overlay_target);
    }









*    function get_tcn(currTarget) {        egCore.pcrud.retrieve('bre',
currTarget, {            select: {bre: ['tcn_value']}
}).then(function(rec) {            $scope.thisTCN = rec.tcn_value();
    console.log("TEST: " + $scope.thisTCN);        });        return
$scope.thisTCN;    };*

**********

This writes the correct TCN value to the console, but it does not always
load that value to $scope.local_overlay_target_tcn. If I have an item
marked for overlay and I load the page, it displays the correct TCN. But,
if I use the interface to select a different item, it keeps the original
TCN in the display.

When I tried setting a regular variable (instead of a $scope variable) in
the "then" part of the chained function, I couldn't access it from outside
that part of the function. Am I creating the thisTCN variable wrong? Or
returning it wrong? Or ... ???


Terran McCanna, PINES Program Manager
------------------------------

Georgia Public Library Service | University System of Georgia

2872 Woodcock Blvd, Suite 250 l Atlanta, GA 30341

(404) 235-7138 | tmccanna at georgialibraries.org

http://help.georgialibraries.org | help at georgialibraries.org

<https://www.facebook.com/georgialibraries>
<https://www.twitter.com/georgialibs>
<https://www.instagram.com/georgialibraries/>
<https://www.twitter.com/georgialibs>

Join our email list <http://georgialibraries.org> for stories of Georgia
libraries making an impact in our communities.



On Wed, Jun 16, 2021 at 4:36 PM Josh Stompro via Eg-newdevs <
eg-newdevs at list.evergreen-ils.org> wrote:

> Terran, I think the get_tcn function is in scope... it just doesn't return
> a value.  I followed the code in the developer console and it does grab the
> tcn.
>
> The function sets the $scope.local_overlay_target_tcn to be equal to the
> found tcn value.  But it doesn't return it.
>
>     function get_tcn(currTarget) {
>         egCore.pcrud.retrieve('bre', currTarget, {
>             select: {bre: ['tcn_value']}
>         }).then(function(rec) {
>             $scope.local_overlay_target_tcn = rec.tcn_value();
>         });
>         return;
>     };
>
> Maybe the function should just return the value... and then instead of
> just calling it like
>
>   } else {
>             $scope.local_overlay_target = items[0]['bibid'];
>             var currTarget = items[0] ['bibid'];
>             get_tcn(currTarget);
>         }
>
> You would use
>
>   } else {
>             $scope.local_overlay_target = items[0]['bibid'];
>             var currTarget = items[0] ['bibid'];
>             $scope.local_overlay_target_tcn = get_tcn(currTarget);
>         }
>
> Josh
> [image: Company logo]
> *Josh Stompro*
>
> *IT Director stomproj at gsuite.larl.org <stomproj at gsuite.larl.org>*
> *218-233-3757 ext. 139* | *Mobile: 218-790-2110*
>
> *Lake Agassiz Regional Library | **www.larl.org <http://www.larl.org>*
> 118 5th ST S
> Moorhead MN 56560
> *Celebrating 60 Years of Service in 2021!*
> _______________________________________________
> Eg-newdevs mailing list
> Eg-newdevs at list.evergreen-ils.org
> http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.evergreen-ils.org/pipermail/eg-newdevs/attachments/20210617/3bd6a001/attachment.html>


More information about the Eg-newdevs mailing list