Announcement

Collapse
No announcement yet.

ajax alert message! returns a field value in ID

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ajax alert message! returns a field value in ID

    hi guys, i am trying get alert message onAfterUpdate and it is working but the field is a foreign key from another table,

    1- so say message says: Room {roomno} was udpated. and that is fine, but i have some rooms with BA BC in the other table, so here I'm getting only the id of the roomno, so how to make the message display the primary value of the field instead of the foreign key?

    2- if i have multiple records form, and user updates 3 or 4 rooms then he will get 3 repeated messages like Room X was updated, Room Y was updated. Room Z was updated.. .all after each other.. how i can make one alert message displays something like this:

    Rooms x,y and Z were updated. should i use the onAfterUpdateAll??

  • #2
    1- Use sc_lookup.

    PHP Code:
    $myquery "SELECT roomno, roomName FROM Rooms WHERE roomno = " . {roomno};
        
    sc_lookup(rs$myquery);

    if (isset({
    rs[0][0]}))     // If there are records on array, something was returned from the query
    {
        
    sc_alert({rs[0][0]}." ".{rs[0][1]})); //message concatenating first and second column 
    }
    else     
    // record not found
    {
        
    sc_alert("It's a trap!!!!");

    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment


    • #3
      All this for a message to convert foreign to primary!!! ok will try that indeed
      remains if i can display all rooms numbers that updated in the same message would be great

      appreciated Giu, thanks a lot

      Comment


      • #4
        Well, this is to obtain the value of a field based on a key. Think about it, you have to lookup the foreign table to obtain the value you need.

        If you want it more short you can always do:
        PHP Code:
        $myquery "SELECT roomno, roomName FROM Rooms WHERE roomno = " . {roomno};    
        sc_lookup(rs$myquery);
        sc_alert({rs[0][1]})); 
        If you will need this code in more apps, create a library with a function, and you just have to do something like:
        [PSEUDOCODE]
        $field = myFunctionReturninRoomName([roomnumber])
        /Giuseppe

        Professional Scriptcase Services
        Some Customers opinions

        Comment


        • #5
          that is what wanted Giu for single room message alert
          i'm learning every day something new here guys, perhaps someone later can explain how to show the alert to obtain all rooms that updated in multiple records view in one message but it is not urgent anyway

          thanks a lot dude

          Mike
          Last edited by MikeDE; 06-12-2014, 04:10 AM.

          Comment


          • #6
            Without thinking too much. Maybe there are better solutions.

            OnApplicationInit:
            PHP Code:
            [message] = "Rooms updated: "
            OnAfterUpdate
            PHP Code:
            [message] = [message] . "{descripcion} with ID {Id}, "
            OnAfterUpdateAll
            PHP Code:
            sc_alert([message]); 
            Remember to set [message] global as OUT on Application->Variable
            Captura2.JPG

            Captura.JPG

            In my situation "name" is in the same table. May you need to extract if want to show roomname in final message.


            OnAfterUpdate
            PHP Code:
            $myquery "SELECT roomno, roomName FROM Rooms WHERE roomno = " . {roomno};    
            sc_lookup(rs$myquery);
            [
            message] = [message] . "{rs[0][1]} with ID {roomno}, "
            /Giuseppe

            Professional Scriptcase Services
            Some Customers opinions

            Comment


            • #7
              May I jump in?

              onLoad: [rooms_updated] = array(); // set [rooms_updated] to OUT

              onAfterUpdate: [rooms_updated][] = {roomno};

              onAfterUpdateAll:

              $query = "SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (". implode(',',[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)
              sc_lookup(upd,$query);
              if(count($upd) > 0)
              {
              $message = 'The following rooms have been updated: '.{upd[0][0]};
              sc_alert($message);
              }

              jsb
              Last edited by jsbinca; 06-11-2014, 12:44 PM.

              Comment


              • #8
                Originally posted by jsbinca View Post
                May I jump in?

                onLoad: [rooms_updated] = array(); // set [rooms_updated] to OUT

                onAfterUpdate: [rooms_updated][] = {roomno};

                onAfterUpdateAll:

                $query = "SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (". implode(',',[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)
                sc_lookup(upd,$query);
                if(count($upd) > 0)
                {
                $message = 'The following rooms have been updated: '.{upd[0][0]};
                sc_alert($message);
                }

                jsb
                Very elegant
                /Giuseppe

                Professional Scriptcase Services
                Some Customers opinions

                Comment


                • #9
                  you are my heros guys, i wasn't wrong when named each one that i learn from him, jsb, aducom, giu, scott, and some other big names here you are really making life easier


                  now that works jsb explained (thankfully) worked perfectly i can see the message displaying all updated rooms in one message nicely sorted





                  i will just apply them to other application after finishing from the 0 values issue


                  cheers
                  Last edited by MikeDE; 06-12-2014, 04:10 AM.

                  Comment


                  • #10
                    Okay guys, this works perfect as stated before, just a little worry if i want to display the other coumn instead of the roomno wanna display the roomdesc in the message, which part should be changed? i tried to change the roomno to roomdesc but didn't work, also changed the [0][0] to [0][1] with no luck

                    i have the roomno now in the table as foreign key and i want to display in the alert the associated roomdesc...

                    the blue arrow instead of the red one.. according to jsb neat code above

                    Untitled.jpg

                    Comment


                    • #11
                      Originally posted by itsme3 View Post
                      Okay guys, this works perfect as stated before, just a little worry if i want to display the other coumn instead of the roomno wanna display the roomdesc in the message, which part should be changed? i tried to change the roomno to roomdesc but didn't work, also changed the [0][0] to [0][1] with no luck

                      i have the roomno now in the table as foreign key and i want to display in the alert the associated roomdesc...

                      the blue arrow instead of the red one.. according to jsb neat code above

                      [ATTACH=CONFIG]1025[/ATTACH]
                      This cant work because query just returns 1 column.
                      Based on the query of jsbinca, If you want to show roomdesc instead roomname
                      This change should work using [0][0]

                      SELECT GROUP_CONCAT(roomname SEPARATOR ', ')
                      SELECT GROUP_CONCAT(roomdesc SEPARATOR ', ')
                      Last edited by Giu; 06-15-2014, 11:13 AM.
                      /Giuseppe

                      Professional Scriptcase Services
                      Some Customers opinions

                      Comment


                      • #12
                        i tried, it didn't, is it because the roomno is not the primary in the small table? i have there "id" which is the primary!

                        it is just giving blank value:: i tried all possible ways, maybe there is something wrong

                        it just says: "Rooms updated: "
                        Last edited by MikeDE; 06-15-2014, 04:31 PM.

                        Comment


                        • #13
                          never mind my last reply guys, i just return it back to roomno and id, got rid of that newly roomdesc field, so now it is working as jsb posted

                          although, i wounder why wasn't working, 90% because the roomno should be the PK

                          cheerz

                          Comment


                          • #14
                            Don't have sense, you can show whatever field you want, an whatever WHERe clause you want, Pk has nothing to do here. Cab you post your code?
                            /Giuseppe

                            Professional Scriptcase Services
                            Some Customers opinions

                            Comment


                            • #15
                              hi Giu,

                              yes it was exactly as jsb did explain thankfully

                              Code:
                              onLoad: [rooms_updated] = array(); // set [rooms_updated] to OUT
                              
                              onAfterUpdate: [rooms_updated][] = {roomno};
                              
                              onAfterUpdateAll:
                              
                              $query = "SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (". implode(',',[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)
                              sc_lookup(upd,$query);
                              if(count($upd) > 0)
                              {
                              $message = 'The following rooms have been updated: '.{upd[0][0]};
                              sc_alert($message);
                              }
                              then when i added that column, i just changed the roomname to roomdesc but was returnning blank value..

                              never mind Giu, its not important now, as i said, i returned the small table as it was, so it is working this way now as stated above,,,

                              i was just curious why wasnt work, because as you said, doesn't make sense....

                              thanks for your care
                              Last edited by MikeDE; 06-16-2014, 05:33 AM.

                              Comment

                              Working...
                              X