No announcement yet.

Field variable won't update

  • Filter
  • Time
  • Show
Clear All
new posts

  • Field variable won't update

    Hi folks,

    I have a form that has a label field (not DB-linked) called {StatusMsg}. In onScriptInit I have a global variable [Status] defined as:

    [Status] = "Ready.";
    In onLoad the form field is set by:

    {StatusMsg} = [Status];
    Now, depending on what the user does on that form, I want the value of {StatusMsg} to change to something else. For example, a button on the form calls another form that does something, plus it changes [Status] to "Awaiting Approval." and then closes returning to the calling form.

    In the calling form I then again execute {StatusMsg} = [Status]; to get the new value. But the form does not reflect the change!?!

    I have tried sc_exit(sel); and sc_exit(ref); in onScriptInit to force a refresh - but that doesn't seem to do anything.

    For a test I created a PHP button with just sc_exit(sel); and clicking the button refreshes the form and shows the new value. So how do I achieve the functionality of that button automatically when returning to the calling form?

    Probably a simple "can't see the wood for the trees" problem, but it's been driving me nuts for the last 2 days. So any thoughts / help gratefully received please.


  • #2
    Most likely if you refresh manually it does reflect the changes? Are you using sc_redir? The you need to set the global variables in the parameter list. Other option is to set the global variable as a session variable.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development /


    • #3
      Hi Albert,

      Yes a manual refresh and the change is seen.

      Are you suggesting using sc_redir to itself (albeit with a parameter)?

      Trying that (sc_redir) also seems to do nothing (I have a test form field with a value of time() to make updates easier to see ). If I click my "refresh" button which uses sc_exit(sel) the time increments every time. When I use sc_exit in my form's event code it does nothing - nor does using sc_redir as you suggest - my field and time test field remain unchanged. Likewise, if I go to a different app via the menu and return, then all the fields are updated.

      Most frustrating and perplexing :-(

      The only other thing that might have a bearing is that the app that "returns" to the calling app is a modal form that I have to manually remove when closing - using:

      echo "<script>window.parent.tb_remove();</script>";
      I use sc_redir from the modal app to "close" the app, and then in the main calling app (I just sc_redir()'d to) I use the above code to remove the modal window. I wonder if that is somehow confusing things in terms of what is open and what has control?
      Last edited by adz1111; 01-11-2015, 09:12 AM.


      • #4
        If you do a sc_redir then a global variable needs to be in the parameter list as the globals are only exchanged if the menu is in the game. I have had similar issues. Doing a modal form means that the global variable changed is still in the context of the modal form and not exchanged as your main menu screen is not refreshed if the modal form returns, only your detail screen, which does not get the global variable. So try to set the global variable to session and see if that helps.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development /


        • #5
          I have made sure they are session variables and that does not help either unfortunately.

          I'm not sure it's the global variables at all. After closing the modal app and returning to the calling app, I can see that the calling app does not re-draw / refresh at all. It's like any call via sc_redir or sc_exit is ignored or has no effect. I believe (but have not tested) that if it wasn't a modal app being called, that the refresh would occur just fine.

          I will trace the code in xdebug (when I get a chance) and see what happens when sc_redir is called.

          Thanks for your help so far.


          • #6
            Since you set [status] to 'Ready' whenever you call the form, it will always be 'Ready'.
            In order to get it right I would suggesst something like:

            if(!isset([status]) || empty([status]))
                [status] = 'Ready';
            When you call an app modal and just close it, nothing will be updated. You have to refresh the form yourself with the help of javascript.

            window.parent.location.href += '';
            Last edited by jsbinca; 01-12-2015, 02:45 PM.


            • #7
              Thanks jsb (sorry for delay, been away for a couple of days)

              Re your first point - I was probably a bit vague - it is always set to "Ready" as that app is always a starting point whenever called. Calls to other apps from there are what will change that status, if at all.

              Re point 2 - that makes a lot of sense. I will give it a go later today and feedback here.

              Thanks again!


              • #8

                Ok I tried that - I put the JS code in the calling app and it does refresh the calling app, but puts it into insert mode, rather than the form displaying the original single record it was on before the modal app came and went.

                The hierarchy / flow is:

                Main Grid app calls (via application link pencil) Single Record Form app
                        ||==> A button on the Single Record Form app calls a Modal Form app                   <===============\\
                                  ||                                                                                          ||
                                  ||                                                                                          ||
                                   \==> Modal Form app makes a change that needs to appear on the Single Record Form app      ||
                                            (This app, when done, needs to be closed, and the change it made reflected in a   ||
                                             field in the calling app - Single Record Form) ==================================//
                Does that make sense?


                • #9

                  echo "<script>parent.document.F1['StatusMsg'].value = 'Awaiting Approval';</script>";
                  echo "<script>parent.window.tb_remove();</script>";

                  You could also use a Javascript button.



                  • #10
                    Sorry for the delay on getting back on this - and thanks so far to jsb and albert for your thoughts.

                    None of those things work though I'm afraid. Over last few weeks I've been pulling my hair out (and I don't have much to begin with) trying to get to the bottom of this before coming back here.

                    What I have done is, via xdebug, prove that control DOES pass back to the calling app (when I force a reload, in various ways) and it does execute statements that update its own fields. However, those updated values do NOT appear changed on the screen. It's almost like the calling app has frozen at the point it refreshes the screen with those values. It hasn't frozen at all though as everything works as you would expect - it's just not up to date. Next time I call that app the updated values are all correct - as does hitting a Refresh button I've added that uses sc_exit(sel) and works fine that way (so what I want is to be able to cause that to happen in code, but running sc-exit etc does not seem to work for this)

                    Sooooo frustrating.

                    Now, it is possible that I am "breaking" something as I have been experimenting with using an alternative to the SC file uploader (using a JS plugin) - and it's when that uploader (called as the aforementioned modal app) closes that I want the calling app to refresh with a field showing the name of the uploaded file (as well as update the DB with that name). The DB update works fine.

                    NOTE: I was planning to document doing this on here separately as a tutorial on how to use a JS plugin like that (as I had to work it out the hard way and wished someone had done something similar) - if I ever get this sorted. I have it all working, aside from 2 final hurdles. This one, and getting it working in my Prod environment (may well be another thread on here when I get to that ha ha). Also, my original description used stuff like "awaiting approval" etc which were just simple terms as I thought describing an analogy of what I was doing would be simpler than explaining the nuts and bolts (probably not in hindsight). :-(

                    Now - I could just give up, leave it, and have a nasty message telling the user to hit the refresh button (horrible, but may end up that way if I cannot resolve this), but I would much prefer the elegant way (and I cannot believe it's not achievable, unless there is a bug, or I have broken a link or something by how I'm integrating a JS plugin?
                    Last edited by adz1111; 02-26-2015, 11:50 AM.


                    • #11

                      So, for the record, this was solved via another post:!-(sc_exit-)

                      Changed my sc_redir as per below - in particular with the "_parent" target:

                      sc_redir(application_x, "", "_parent");
                      This worked by closing the modal app and then allowing the calling app to refresh - Hallelujah! Such a minor omission causing major hair loss. Phew!

                      Kudos to the folks in the post above!