<div dir="ltr"><div dir="ltr">get_tcn() performs a network request in the background and the function you pass to .then() doesn't run right away - it's just set up to run when the response comes back. The program keeps going in the meantime, so the dialog will likely run before you get a response and assign the tcn value. To make the dialog not happen until you get the tcn_value, you need to wrap it in the .then() function as well.<br><br>Can I suggest an alternative approach? You can store the TCN in local storage earlier, just like the bib ID, and grab it the same way in the $scope.overlay_target function. This would also eliminate a need for the first get_tcn call above the $scope.mark_as_overlay_target function.</div><div dir="ltr"><br></div><div dir="ltr">For example:<br><br>$scope.local_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;<br><b><font color="#38761d">$scope.local_overlay_target_tcn = egCore.hatch.getLocalItem('eg.cat.marked_overlay_tcn') || 0;</font></b><br>$scope.mark_as_overlay_target = function() {<br><br>Then at the end of the function:<br><br>egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.local_overlay_target);<br><b><font color="#38761d">egCore.hatch.setLocalItem('eg.cat.marked_overlay_tcn',$scope.local_overlay_target_tcn);</font></b><br><br>Then in the $scope.overlay_record function you can simply grab it instead of making a network call:<br><br>var overlay_target = $scope.local_overlay_target;<br><b><font color="#38761d">var overlay_target_tcn = $scope.local_overlay_target_tcn;</font></b><br>var live_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;<br><b><font color="#38761d">var live_overlay_target_tcn = egCore.hatch.getLocalItem('eg.cat.marked_overlay_tcn') || 0;</font></b><br><br>and pass it to the dialog (assuming you're adding tcn and live_tcn in z3950_strings.tt2):<br><br>egConfirmDialog.open(<br> confirm_title,<br> confirm_msg,<br> { id : overlay_target, live_id : live_overlay_target<font color="#38761d"><b>,</b><br> <b>tcn : overlay_target_tcn, live_tcn: live_overlay_target_tcn</b></font> }<br><br>Finally, you can clear them at the end:<br><br>$scope.local_overlay_target = 0;<br><b><font color="#38761d">$scope.local_overlay_target_tcn = 0;</font></b><br>egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');<br><b><font color="#38761d">egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record_tcn');</font></b><br><br>I also noticed, in the $scope.mark_as_overlay_target function, we already have the selected item as a fleshed bre object, which includes the MARC, in items[0]. So, if the TCN value always comes from 901 a (does it?), you might not need the get_tcn function at all and could just get the 901 a from items[0]['marcxml'] in the $scope.mark_as_overlay_target function:<br><br>$scope.local_overlay_target = items[0]['bibid'];<br><b><font color="#38761d">var tcnSubfield = new MARC21.Record({<br> marcxml: items[0]['marcxml']<br>}).subfield('901', 'a');<br>$scope.local_overlay_target_tcn = tcnSubfield === null<br> ? $scope.local_overlay_target<br> : tcnSubfield[1];</font></b><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 17, 2021 at 5:44 PM Terran McCanna <<a href="mailto:tmccanna@georgialibraries.org">tmccanna@georgialibraries.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Ack, hit send before I was done. I am getting the correct value in the console with this part, but it's not letting me grab that value from <br></div><div><br></div><div>
$scope.overlay_record = function() {<br> var items = $scope.gridControls.selectedItems();<br> var overlay_target = $scope.local_overlay_target;<br> <b>var overlay_target_tcn = $scope.local_overlay_target_tcn; <span style="color:rgb(255,0,0)"><--this part works and I can display it in the popup</span></b><br> var live_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;<br> <b>get_tcn(live_overlay_target).then(function(rec) {<br> $scope.live_overlay_target_tcn = rec.tcn_value();<br> console.log('LIVE TCN: ' + $scope.live_overlay_target_tcn);<span style="color:rgb(255,0,0)">
<--this grabs correct tcn</span><br> });</b>
<br></div><div><br></div><div>But if I try to grab $scope.live_overlay_target_tcn for the popup then it says it's undefined. :(<br></div><div><br></div><div><br></div><div><br></div><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br><div dir="ltr" style="margin-left:0pt"><table style="border:medium none;border-collapse:collapse"><colgroup><col width="94"><col width="530"></colgroup><tbody><tr style="height:123pt"><td style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:75px;height:75px"><img src="https://lh6.googleusercontent.com/fJoF6o0xl9XByQZmykva1sv2n_cKGUXL_BH4crkpJgSqDu-yU7-5jIypuXBsEuoXCCBAAUQ2jUztJlZDNUVOlwl1bWZIL1W4wmFuEEzCLVMxUyhzdkV7jkcRcdZZni2z8OPz4xJA" style="margin-left: 0px; margin-top: 0px;" width="75" height="75"></span></span></p></td><td style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:11pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Terran McCanna, PINES Program Manager</span></p><hr><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:10pt;font-family:Verdana;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"></span><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Georgia Public Library Service | University System of Georgia</span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">2872 Woodcock Blvd, Suite 250 l Atlanta, GA 30341</span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">(404) 235-7138</span><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> | <a href="mailto:tmccanna@georgialibraries.org" target="_blank">tmccanna@georgialibraries.org</a> <br></span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><a href="http://help.georgialibraries.org" target="_blank">http://help.georgialibraries.org</a> | <a href="mailto:help@georgialibraries.org" target="_blank">help@georgialibraries.org</a><br></span></p><br><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><a href="https://www.facebook.com/georgialibraries" style="text-decoration:none" target="_blank"><span style="font-size:9pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:36px;height:36px"><img src="https://lh4.googleusercontent.com/77DYzuoZ-zqC0pyQuYNKCrWaPuOANHsYTJze0JxE_iK4yW2sCswywdPCC8hCHOIyhO7KKIO-L6dlN1wIqdHFcyJmTa1fuc5Ok34dR8FQTtZHawpgNmovGxjg9RS0-WI74dFDHw0_" style="margin-left: 0px; margin-top: 0px;" width="36" height="36"></span></span></a><a href="https://www.twitter.com/georgialibs" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:35px;height:35px"><img src="https://lh4.googleusercontent.com/1bKX66xWgHe-v5FD5l-hYX4FrZDXi1Y2aKr0DZLDA_oEHy7s01WVqgVilQcwGBzRQZAg3yOePmZncGwtiYGSgavOkb0T5Tj3c46iUJ7ZE7h-MUEhVwXQs7Oc3cahIYMN2SGlk_6b" style="margin-left: 0px; margin-top: 0px;" width="35" height="35"></span></span></a><a href="https://www.instagram.com/georgialibraries/" style="text-decoration:none" target="_blank"><span style="font-size:11pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:34px;height:34px"><img src="https://lh3.googleusercontent.com/U7PH5YIQnuRvbeMnGOlJAEPAre7Zqx_I6IDJAtJVwUDCp1-TmjSwP_x21qKx8ApsbcaILIuSpL3Pzau2Rz-phR_4IPcLR4LrIha_JMDHqombNtsfa1uhXcYS02QWTAyYqSf3ES_n" style="margin-left: 0px; margin-top: 0px;" width="34" height="34"></span></span></a><a href="https://www.twitter.com/georgialibs" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"></span></a></p></td></tr><tr style="height:21pt"><td colspan="2" style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;text-align:center"><a href="http://georgialibraries.org" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">Join our email list</span></a><span style="font-size:10pt;font-family:Verdana;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:10pt;font-family:Verdana;color:rgb(67,67,67);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">for stories of Georgia libraries making an impact in our communities.</span></p></td></tr></tbody></table></div><br></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 17, 2021 at 5:39 PM Terran McCanna <<a href="mailto:tmccanna@georgialibraries.org" target="_blank">tmccanna@georgialibraries.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I followed Dan's advice and the original bug is now working properly, and I realized that since we have already set $scope.local_overlay_target_tcn that we can access that in the message, but I'm still struggling to understand how to get the other "live" value to appear in the pop-up message. <br></div><div><br></div><div> $scope.overlay_record = function() {<br> var items = $scope.gridControls.selectedItems();<br> var overlay_target = $scope.local_overlay_target;<br> <b>var overlay_target_tcn = $scope.local_overlay_target_tcn; <span style="color:rgb(255,0,0)"><--this part works</span></b><br> var live_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;<br> <b>get_tcn(live_overlay_target).then(function(rec) {<br> $scope.live_overlay_target_tcn = rec.tcn_value();<br> console.log('LIVE TCN: ' + $scope.live_overlay_target_tcn);<br> });</b></div><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br><div dir="ltr" style="margin-left:0pt"><table style="border:medium none;border-collapse:collapse"><colgroup><col width="94"><col width="530"></colgroup><tbody><tr style="height:123pt"><td style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:75px;height:75px"><img src="https://lh6.googleusercontent.com/fJoF6o0xl9XByQZmykva1sv2n_cKGUXL_BH4crkpJgSqDu-yU7-5jIypuXBsEuoXCCBAAUQ2jUztJlZDNUVOlwl1bWZIL1W4wmFuEEzCLVMxUyhzdkV7jkcRcdZZni2z8OPz4xJA" style="margin-left: 0px; margin-top: 0px;" width="75" height="75"></span></span></p></td><td style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:11pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Terran McCanna, PINES Program Manager</span></p><hr><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:10pt;font-family:Verdana;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"></span><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Georgia Public Library Service | University System of Georgia</span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">2872 Woodcock Blvd, Suite 250 l Atlanta, GA 30341</span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">(404) 235-7138</span><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> | <a href="mailto:tmccanna@georgialibraries.org" target="_blank">tmccanna@georgialibraries.org</a> <br></span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><a href="http://help.georgialibraries.org" target="_blank">http://help.georgialibraries.org</a> | <a href="mailto:help@georgialibraries.org" target="_blank">help@georgialibraries.org</a><br></span></p><br><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><a href="https://www.facebook.com/georgialibraries" style="text-decoration:none" target="_blank"><span style="font-size:9pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:36px;height:36px"><img src="https://lh4.googleusercontent.com/77DYzuoZ-zqC0pyQuYNKCrWaPuOANHsYTJze0JxE_iK4yW2sCswywdPCC8hCHOIyhO7KKIO-L6dlN1wIqdHFcyJmTa1fuc5Ok34dR8FQTtZHawpgNmovGxjg9RS0-WI74dFDHw0_" style="margin-left: 0px; margin-top: 0px;" width="36" height="36"></span></span></a><a href="https://www.twitter.com/georgialibs" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:35px;height:35px"><img src="https://lh4.googleusercontent.com/1bKX66xWgHe-v5FD5l-hYX4FrZDXi1Y2aKr0DZLDA_oEHy7s01WVqgVilQcwGBzRQZAg3yOePmZncGwtiYGSgavOkb0T5Tj3c46iUJ7ZE7h-MUEhVwXQs7Oc3cahIYMN2SGlk_6b" style="margin-left: 0px; margin-top: 0px;" width="35" height="35"></span></span></a><a href="https://www.instagram.com/georgialibraries/" style="text-decoration:none" target="_blank"><span style="font-size:11pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:34px;height:34px"><img src="https://lh3.googleusercontent.com/U7PH5YIQnuRvbeMnGOlJAEPAre7Zqx_I6IDJAtJVwUDCp1-TmjSwP_x21qKx8ApsbcaILIuSpL3Pzau2Rz-phR_4IPcLR4LrIha_JMDHqombNtsfa1uhXcYS02QWTAyYqSf3ES_n" style="margin-left: 0px; margin-top: 0px;" width="34" height="34"></span></span></a><a href="https://www.twitter.com/georgialibs" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"></span></a></p></td></tr><tr style="height:21pt"><td colspan="2" style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;text-align:center"><a href="http://georgialibraries.org" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">Join our email list</span></a><span style="font-size:10pt;font-family:Verdana;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:10pt;font-family:Verdana;color:rgb(67,67,67);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">for stories of Georgia libraries making an impact in our communities.</span></p></td></tr></tbody></table></div><br></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 17, 2021 at 2:46 PM Josh Stompro <<a href="mailto:stomproj@gsuite.larl.org" target="_blank">stomproj@gsuite.larl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thank you Dan, that was very helpful to understand what wasn't working. <div><br></div><div>To answer your last question, we were trying to allow the get_tcn function to be more generic, so it could be used to grab the TCNs for an error message that pops up when you choose a different overlay target in another tab, then switch back to the original tab and try to overlay. See this ticket. <a href="https://bugs.launchpad.net/evergreen/+bug/1932199" target="_blank">https://bugs.launchpad.net/evergreen/+bug/1932199</a></div><div><br></div><div>So we want to pull in the TCN for both old and new overlay targets and display them to the user. </div><div><br></div><div>Like so</div><div> if (overlay_target != live_overlay_target) {<br> var confirm_title = egCore.strings.OVERLAY_CHANGED_TITLE;<br> var confirm_msg = egCore.strings.OVERLAY_CHANGED;<br><br> if (live_overlay_target == 0) { // someone unset the target...<br> confirm_title = egCore.strings.OVERLAY_REMOVED_TITLE;<br> confirm_msg = egCore.strings.OVERLAY_REMOVED;<br> }<br><br> egConfirmDialog.open(<br> confirm_title,<br> confirm_msg,<br> { id : overlay_target, live_id : live_overlay_target, id_tcn :<br> <b> get_tcn(overlay_target)</b>, live_id_tcn : <b>get_tcn(live_overlay_target</b>)}<br></div><div><br></div><div><br></div><div><br></div><div>Josh</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 17, 2021 at 1:33 PM Dan Briem via Eg-newdevs <<a href="mailto:eg-newdevs@list.evergreen-ils.org" target="_blank">eg-newdevs@list.evergreen-ils.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">egCore.pcrud.retrieve is a promise. The idea is that it needs to run a network request and you don't want your program to stall while waiting for a response back. So, with promises, the .then() doesn't run right away - it's like you're just setting it up to run later when the response comes back, and in the meantime your program will continue on to the next line while that promise is doing its thing.<div><br></div><div>So the order things happen:<br><div><ol><li>send request</li><li>return $scope.thisTCN (undefined probably?)</li><li>response comes back and $scope.thisTCN is set to rec.tcn_value()</li></ol><div>The next time it runs:</div></div></div><div><ol><li>send request</li><li>return $scope.thisTCN (previous value it was set to before)</li><li>response comes back and $scope.thisTCN is set to rec.tcn_value()</li></ol><div>If you want to wrap the egCore.pcrud call in its own function and return the value, you could just return the whole promise and then call get_tcn(someRecordId).then() when you want to assign $scope.local_overlay_target_tcn. For example:</div></div><div><br></div><div>get_tcn($scope.local_overlay_target).then(function(rec) {<br> $scope.local_overlay_target_tcn = rec.tcn_value();<br>});</div><div><br></div><div>...........</div><div><br></div><div>function get_tcn(currTarget) {<br> return egCore.pcrud.retrieve('bre', currTarget, {<br> select: {bre: ['tcn_value']}<br> });<br>}</div><div><br></div><div>This assumes you aren't using $scope.thisTCN anywhere else and can just remove that assignment.</div><div><br></div><div>I'm also curious, because I looked at the patch you shared before the meeting, what wasn't working about it? (the reason I ask is because this should be close to the same thing)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 17, 2021 at 1:12 PM Terran McCanna via Eg-newdevs <<a href="mailto:eg-newdevs@list.evergreen-ils.org" target="_blank">eg-newdevs@list.evergreen-ils.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>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:</div><div><br></div><div><a href="https://screencast-o-matic.com/watch/cr1bDNV16uo" target="_blank">https://screencast-o-matic.com/watch/cr1bDNV16uo</a></div><div><br></div><div>
********** <br></div><div><br></div><div> $scope.local_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;<br> if($scope.local_overlay_target) {<br> var currTarget = $scope.local_overlay_target;<br> <b> $scope.local_overlay_target_tcn = get_tcn(currTarget);</b><br> }<br> $scope.mark_as_overlay_target = function() {<br> var items = $scope.gridControls.selectedItems();<br> if ($scope.local_overlay_target == items[0]['bibid']) {<br> $scope.local_overlay_target = 0;<br> $scope.local_overlay_target_tcn = 0;<br> } else {<br> $scope.local_overlay_target = items[0]['bibid'];<br> var currTarget = items[0]['bibid'];<br> <b>$scope.local_overlay_target_tcn = get_tcn(currTarget);</b><br> }<br> egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.local_overlay_target);<br> }</div><div><br></div><div><b> function get_tcn(currTarget) {<br> egCore.pcrud.retrieve('bre', currTarget, {<br> select: {bre: ['tcn_value']}<br> }).then(function(rec) {<br> $scope.thisTCN = rec.tcn_value();<br> console.log("TEST: " + $scope.thisTCN);<br> });<br> return $scope.thisTCN;<br> };</b></div><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br></div><div>**********</div><div><br></div><div>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. <br></div><div><br></div><div>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 ... ???<br></div><div><br></div><div><br></div><div><div dir="ltr" style="margin-left:0pt"><table style="border:medium none;border-collapse:collapse"><colgroup><col width="94"><col width="530"></colgroup><tbody><tr style="height:123pt"><td style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:75px;height:75px"><img src="https://lh6.googleusercontent.com/fJoF6o0xl9XByQZmykva1sv2n_cKGUXL_BH4crkpJgSqDu-yU7-5jIypuXBsEuoXCCBAAUQ2jUztJlZDNUVOlwl1bWZIL1W4wmFuEEzCLVMxUyhzdkV7jkcRcdZZni2z8OPz4xJA" style="margin-left: 0px; margin-top: 0px;" width="75" height="75"></span></span></p></td><td style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:11pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Terran McCanna, PINES Program Manager</span></p><hr><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:10pt;font-family:Verdana;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"></span><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Georgia Public Library Service | University System of Georgia</span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">2872 Woodcock Blvd, Suite 250 l Atlanta, GA 30341</span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">(404) 235-7138</span><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> | <a href="mailto:tmccanna@georgialibraries.org" target="_blank">tmccanna@georgialibraries.org</a> <br></span></p><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><span style="font-size:9pt;font-family:Verdana;color:rgb(30,67,155);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><a href="http://help.georgialibraries.org" target="_blank">http://help.georgialibraries.org</a> | <a href="mailto:help@georgialibraries.org" target="_blank">help@georgialibraries.org</a><br></span></p><br><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;margin-left:9pt"><a href="https://www.facebook.com/georgialibraries" style="text-decoration:none" target="_blank"><span style="font-size:9pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:36px;height:36px"><img src="https://lh4.googleusercontent.com/77DYzuoZ-zqC0pyQuYNKCrWaPuOANHsYTJze0JxE_iK4yW2sCswywdPCC8hCHOIyhO7KKIO-L6dlN1wIqdHFcyJmTa1fuc5Ok34dR8FQTtZHawpgNmovGxjg9RS0-WI74dFDHw0_" style="margin-left: 0px; margin-top: 0px;" width="36" height="36"></span></span></a><a href="https://www.twitter.com/georgialibs" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:35px;height:35px"><img src="https://lh4.googleusercontent.com/1bKX66xWgHe-v5FD5l-hYX4FrZDXi1Y2aKr0DZLDA_oEHy7s01WVqgVilQcwGBzRQZAg3yOePmZncGwtiYGSgavOkb0T5Tj3c46iUJ7ZE7h-MUEhVwXQs7Oc3cahIYMN2SGlk_6b" style="margin-left: 0px; margin-top: 0px;" width="35" height="35"></span></span></a><a href="https://www.instagram.com/georgialibraries/" style="text-decoration:none" target="_blank"><span style="font-size:11pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><span style="border:medium none;display:inline-block;overflow:hidden;width:34px;height:34px"><img src="https://lh3.googleusercontent.com/U7PH5YIQnuRvbeMnGOlJAEPAre7Zqx_I6IDJAtJVwUDCp1-TmjSwP_x21qKx8ApsbcaILIuSpL3Pzau2Rz-phR_4IPcLR4LrIha_JMDHqombNtsfa1uhXcYS02QWTAyYqSf3ES_n" style="margin-left: 0px; margin-top: 0px;" width="34" height="34"></span></span></a><a href="https://www.twitter.com/georgialibs" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"></span></a></p></td></tr><tr style="height:21pt"><td colspan="2" style="vertical-align:top;padding:5pt"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;text-align:center"><a href="http://georgialibraries.org" style="text-decoration:none" target="_blank"><span style="font-size:10pt;font-family:Verdana;color:rgb(17,85,204);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">Join our email list</span></a><span style="font-size:10pt;font-family:Verdana;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:10pt;font-family:Verdana;color:rgb(67,67,67);background-color:rgb(255,255,255);font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">for stories of Georgia libraries making an impact in our communities.</span></p></td></tr></tbody></table></div><br></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 16, 2021 at 4:36 PM Josh Stompro via Eg-newdevs <<a href="mailto:eg-newdevs@list.evergreen-ils.org" target="_blank">eg-newdevs@list.evergreen-ils.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">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.<div><br></div><div>The function sets the $scope.local_overlay_target_tcn to be equal to the found tcn value. But it doesn't return it.</div><div><br></div><div> function get_tcn(currTarget) {<br> egCore.pcrud.retrieve('bre', currTarget, {<br> select: {bre: ['tcn_value']}<br> }).then(function(rec) {<br> $scope.local_overlay_target_tcn = rec.tcn_value();<br> });<br> return;<br> };</div><div><br></div><div>Maybe the function should just return the value... and then instead of just calling it like</div><div><br></div><div> } else {<br> $scope.local_overlay_target = items[0]['bibid'];<br> var currTarget = items[0] ['bibid'];<br> get_tcn(currTarget);<br> }</div><div><br></div><div>You would use</div><div><br></div><div> } else {<br> $scope.local_overlay_target = items[0]['bibid'];<br> var currTarget = items[0] ['bibid'];<br> $scope.local_overlay_target_tcn = get_tcn(currTarget);<br> }</div><div><br></div><div>Josh</div><div><div><div dir="ltr"><table style="padding:0px;margin:10px 0px;border:medium none"><tbody><tr><td style="vertical-align:middle;padding:0px 7px 0px 0px"><img alt="Company logo" src="https://storage.googleapis.com/signaturesatori/customer-C039u5c5y/images/GJnfy.png" width="100" height="100"></td><td style="border-left:3px solid rgb(232,232,232);padding:7px 0px 0px 10px">
<div style="font-family:arial,helvetica,sans-serif;font-size:14px;line-height:17px;font-weight:bold;color:rgb(238,142,22)"><span style="font-size:16px"><b>Josh Stompro</b></span></div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12px;line-height:14px;font-weight:normal;color:rgb(0,0,0);margin-bottom:10px"><span style="font-size:13px"><b><i>IT Director</i><br>
<a href="mailto:stomproj@gsuite.larl.org" style="text-decoration:none;color:rgb(27,70,153)" target="_blank">stomproj@gsuite.larl.org</a></b><br>
<b>218-233-3757 ext. 139</b> </span><span style="font-size:13px"><span style="color:rgb(1,186,239)">| </span><b>Mobile: 218-790-2110</b></span><br>
<br>
<span style="font-size:13px"><b><span style="color:rgb(27,70,152)">Lake Agassiz Regional Library | </span></b></span><span style="font-size:13px"><b><a href="http://www.larl.org" style="text-decoration:none;color:rgb(27,70,153)" target="_blank">www.larl.org</a></b><br>
118 5th ST S<br>Moorhead MN 56560<br>
<span style="color:rgb(1,186,239)"><i><b>Celebrating 60 Years of Service in 2021!</b></i></span></span></div>
</td></tr></tbody></table>
</div></div></div></div>
_______________________________________________<br>
Eg-newdevs mailing list<br>
<a href="mailto:Eg-newdevs@list.evergreen-ils.org" target="_blank">Eg-newdevs@list.evergreen-ils.org</a><br>
<a href="http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs" rel="noreferrer" target="_blank">http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs</a><br>
</blockquote></div>
_______________________________________________<br>
Eg-newdevs mailing list<br>
<a href="mailto:Eg-newdevs@list.evergreen-ils.org" target="_blank">Eg-newdevs@list.evergreen-ils.org</a><br>
<a href="http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs" rel="noreferrer" target="_blank">http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div>Dan Briem<br>Harrison Public Library</div><div>2 Bruce Ave. Harrison, NY 10528</div><div>(914) 835-0324<br><div><a href="https://www.harrisonpl.org" target="_blank">harrisonpl.org</a></div></div></div></div></div></div>
_______________________________________________<br>
Eg-newdevs mailing list<br>
<a href="mailto:Eg-newdevs@list.evergreen-ils.org" target="_blank">Eg-newdevs@list.evergreen-ils.org</a><br>
<a href="http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs" rel="noreferrer" target="_blank">http://list.evergreen-ils.org/cgi-bin/mailman/listinfo/eg-newdevs</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><div>Dan</div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div></div></div></div></div></div></div></div>