2 Replies Latest reply on Mar 20, 2013 1:22 PM by Kyle Spiller

    Can't seem to populate the hash in a create operation

      This is the code in by delivery.rb source adapter for an application consuming a SOAP based web service:

       

      def create(create_hash)

          puts(">>>>>>>>>>>>>> RHOCONNECT Delivery create")

          @session_ID = Store.get_value("session_ID")

          deliveryinfo = {

            :_CONDITION => create_hash[:condition],

            :_DATE => create_hash[:date],

            :_NOTES => create_hash[:notes],

            :_PRO => create_hash[:pro],

            :_SIGNEDBY => create_hash[:signedby],

            :_STATUS => create_hash[:status],

            :_TIMEIN => create_hash[:timein],

            :_TIMEOUT => create_hash[:timeout]

          }

          puts " >>>>>>>>>>>>>>> deliveryinfo values"

          puts "               Condition: " + deliveryinfo[:condition].to_s

          puts "                    Date: " + deliveryinfo[:date].to_s

          puts "                     Pro: " + deliveryinfo[:pro].to_s

          puts "                   Notes: " + deliveryinfo[:notes].to_s

          puts "                SignedBy: " + deliveryinfo[:signedby].to_s

          puts "                  Status: " + deliveryinfo[:status].to_s

          puts "                 Time In: " + deliveryinfo[:timein].to_s

          puts "                Time Out: " + deliveryinfo[:timeout].to_s

            body = {

            :param0 =>

            {

            :_SESSIONID => @session_ID,

            :_DELIVERYINFO => deliveryinfo

            }

          }

          $webserviceurl= Store.get_value("webserviceurl")

          @client = Savon.client( :wsdl => $webserviceurl)

          data = @client.call(:deliver) do

            message(body)

          end

          @result = {}

          res = data.to_hash[:deliverResponse]

        end

       

      The corresponding delivery code on the Rhomobile side looks like this:

        <div data-role="content">

          <form method="POST" action="<%= url_for :action => :create %>">

         <input type="hidden" name="id" value="<%= @delivery.object %>"/>

          <input type="hidden" id="delivery[pro]" name="delivery[pro]"  value="<%= $pro %>" />

               <div data-role="fieldcontain">

                 <label for="delivery[date]" class="fieldLabel">Date</label>

                  <input  required="required" type="text" id="delivery[date]" name="delivery[date]"  value="<%= Time.now.strftime("%m/%d/%Y %I:%M%p") %>" <%= placeholder("Date") %> /> -

                </div>

                    <div data-role="fieldcontain">

                      <label for="delivery[condition]" class="fieldLabel">Condition</label>           

                        <select id="delivery[condition]" name="delivery[condition]" <%= placeholder("Condition") %> >

                        <option value="C">CLEAR</option>

                        <option value="D">DAMAGED</option>

                        <option value="O">OVER</option>

                        <option value="S">SHORT</option>

                        </select>

                    </div>

               <div data-role="fieldcontain">

                  <label for="delivery[notes]" class="fieldLabel">Notes</label>

                  <input type="text" width="100%" id="delivery[notes]" name="delivery[notes]" <%= placeholder("Notes") %> />

                </div>

               <div data-role="fieldcontain">

                  <label for="delivery[signedby]" class="fieldLabel" required="required">Signed by</label>

                  <input type="text" id="delivery[signedby]" name="delivery[signedby]" <%= placeholder("Signedby") %> />

                </div>

               <div data-role="fieldcontain">

                  <label for="delivery[status]" class="fieldLabel">Status</label>

                 <select id="delivery[status]" name="delivery[status]" <%= placeholder("Status") %> >

                    <option>DELV</option>

                    <option>OFD</option>

                    <option>PKUP</option>

                    <option>RTD</option>

                    <option>APPT</option>

                    <option>REFUS</option>

                  </select>

                </div>

                <div data-role="fieldcontain">

                  <label for="delivery[timein]" class="fieldLabel">Time In</label>

                  <input type="text" id="delivery[timein]" required="required" value = "<%= Time.now.strftime('%I:%M%p') %>" name="delivery[timein]" <%= placeholder("Timein") %> />

                </div>

            <input type="submit" value="Save"/>

          </form>

       

      The debugging statements in bold in the first code sample show that the hash has no values assigned to any of its members. I am quite new to Rho, so it's probably something glaringly obvious, but I am stumped.

        • Re: Can't seem to populate the hash in a create operation

          Kyle

           

          It looks like maybe you are not referencing the keys properly for the create_hash variable.

           

          You may want to:

          def create(create_hash)
              puts(">>>>>>>>>>>>>> RHOCONNECT Delivery create")
               puts create_hash.keys
          
          


          createhash = {'stringfield' => "mystring",'datefield' => time1, 'intfield' => 10, 'boolfield' => true}
          will yield
          1.9.3p194 :016 > createhash.keys                                                 
          => ["stringfield", "datefield", "intfield", "boolfield"]
          
          # createhash["stringfield"]
          

          but

          createhash = {:stringfield => "mystring",:datefield => time1, :intfield => 10, :boolfield => true}
          will yield
          1.9.3p194 :019 > createhash.keys                                                 
          => [:stringfield, :datefield, :intfield, :boolfield]
          
          #  createhash[:stringfield]
          l
          

           

           

          Some general info on hashes: http://www.tutorialspoint.com/ruby/ruby_hashes.htm

           

          Also some Ruby fundamentals covered at the last AppForum that may be helpful:

          https://developer.motorolasolutions.com/docs/DOC-1635