We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36009
    • 10 Posts
    Hey, I have a question regarding using getObject retrieval. If I hardcode my variables:

    [[!editPredictions? &userdata_id=`49` &week=`Week 1`]]

    I am able to retieve my object.
    However, if I use:

    [[!editPredictions? &userdata_id=`[[+userdata_id]]` &week=`[[!getResourceField? &id=`[[getResourceField? &id=`89` &field=`currentWeek` &processTV=`1`]]` &field=`pagetitle` ]]`]]

    I get nothing, although my script echoes back '49' and 'Week 1' as expected if I check. My database show the same entries where expected, in fact the same script populates the database with the entries as passed from the placeholders, but only retrieves them when I replace with their hardcoded equivelents.
    My getobject statement is:

    $predictions = $modx->getObject('Predictions',
    array('week' => $week, 'userdata_id' => $userdata_id));

    Is it some sort of datatype/key issue maybe?

    Thank you,
    Conor

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      More likely an issue with the parsing order. You have very deeply nested tags and each has to be processed at the right time in order for the whole thing to work.

      What is setting the userdata_id placeholder?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36009
        • 10 Posts
        Hi Bob,
        Thanks for the thoughts, most of the code is reused from your tutorials too smiley

        userdata_id is coming from [[!profile]]
        I agree there is a lot of nesting.. the confusing thing is that it resolves fine and I can echo the correct results out in the script that I pass it to.
        Also, if I only hardcode one or the other, it also fails, so it seems that neither is ultimately working. Thus I was wondering about datatypes/Keys.
        Seems very strange I know.. any ideas and all greatly appreciated.
        • discuss.answer
          • 3749
          • 24,544 Posts
          I see that you also have a getResourceField tag inside another getResourceField tag. wink

          Calling the first one uncached delays its processing, so it may not be available when the outer tag is processed.

          In situations like this, I find it's usually much faster and less frustrating to create a single custom snippet to do the whole job rather than try to figure out what's going on with the caching.

          If I'm understanding what you're doing, I would move the determination of the week inside the editPredictions snippet.

          I'm making some wild guesses here, but this might get you started:


          $userdata_id = $modx->getOption('userdata_id', $scriptProperties);
          
          $currentWeekTvId = 12; // set to ID of currentWeek TV
          $currentWeekResourceId = 89; // set to ID of the resource holding the currentWeekTV value you want
          
          $tv = $modx->getObject('modTemplateVar', $currentWeekTvId);
          $tvVal = $tv->renderOutput($currentWeekResourceId);
          
          $resource = $modx->getObject('modResource', $tvVal);
          
          if ($resource) {
             $week = $resource->get('pagetitle');
          } else {
             /* handle error */
          }
          
          $predictions = $modx->getObject('Predictions',
          array('week' => $week, 'userdata_id' => $userdata_id));
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36009
            • 10 Posts
            Hi Bob,
            Thank you so much for your kind help.
            I hate to say this, but returning to it this evening I realised that after fixing one typo I never reverted and reran my tests from the start. In any case I had removed [[!ExtUserUpdateProfile]] and this was setting [[+userdata_id]] not [[!Profile]] (the critical question you asked).
            Schoolboy error and the sort of thing that happens to me far too often at 3am.

            Your code above is nonetheless very interesting and graceful and I will implement it as a better solution.

            As I mentioned I have made extensive use of your brilliant tutorials which have been immensely valuable to me. As penance for wasting your time (but moreso as a gift to myself) I'll be purchasing your book this evening.

            Thank you so much for taking the time to put me on the right path.
            Best regards,

            Conor
              • 3749
              • 24,544 Posts
              Thanks for the kind words. I'm glad I could help. smiley
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting