Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Button to create parent record, get id and place id in child record

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

    Button to create parent record, get id and place id in child record

    HI all,

    I'm working on my very first button, and once I get this, I'm sure to use this same process hundreds of times elsewhere.

    I'm working from the detail view on a grid based on a Customers table and what I want to do is have a button that concatenates Account+"_"+Dove_Account into a variable then creates a new record in Group_Accounts (there are only 2 fields group_account_ID and Group_Name) then places the variable in the Group_Name field, save the record and captures the created id in a variable to bring back to the original record where the button was clicked and enters the id variable in the group_id field to join the 2 records.

    Any assistance is appreciated.

    Marc
    Thanks,

    Marc McCall

    Version 12.3 2128 -4292
    MySQL backend

    If at first you don�t succeed, call it version 1.0

    #2
    Re: Button to create parent record, get id and place id in child record

    Sounds like you will be needing to write some SQL queries to do all that.

    Can trigger using your button click event and run some server side xbasic and even then return some javascript via callback to do stuff in your browser (e.g. refresh grid, etc)

    See the code I posted here, which was for deleting a record using connection.execute
    https://forum.alphasoftware.com/showthread.php?110280#5

    The concept is similar to how you could achieve your goal
    Write your SQL code
    Run it using connection.execute

    Also, you don't have to use stored procedures on the backend if you don't want to (or if your database does not support SP's)
    You can create the SQL statements in Xbasic and then run them on the database using the connection object.

    Comment


      #3
      Re: Button to create parent record, get id and place id in child record

      Thanks for the reply Mixter, It is going to take me a little bit top wrap my head around it. I'm finding out that AA is not as easy to use as I thought is was going to be.
      Thanks,

      Marc McCall

      Version 12.3 2128 -4292
      MySQL backend

      If at first you don�t succeed, call it version 1.0

      Comment


        #4
        Re: Button to create parent record, get id and place id in child record

        Originally posted by DDPMarc View Post
        Thanks for the reply Mixter, It is going to take me a little bit top wrap my head around it. I'm finding out that AA is not as easy to use as I thought is was going to be.
        Learning curve, as time goes on it gets better.
        Back to your post where does the account and dove_account come from, account is probably an account number from customer! but dove_account? Unless it is something I should know, as every one should.
        And what is your database back end dbf or SQL?
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #5
          Re: Button to create parent record, get id and place id in child record

          Account is the account name from customers table, dove_account is the account number from customers table.It isn't the id in this situation but where all of the data is coming from it is.

          I'm building a utility program that manipulates the data from our CRM and preps it to be added to to an ecommerce system.
          Thanks,

          Marc McCall

          Version 12.3 2128 -4292
          MySQL backend

          If at first you don�t succeed, call it version 1.0

          Comment


            #6
            Re: Button to create parent record, get id and place id in child record

            you need to create an ajax callback to insert the data into the second table and grab the last_insert_id and then update the first table the corresponding field.
            this all can be done via xbasic, inserting the last_insert_id can be done as a trigger after insert if you like. but if you go that way make yourself a comment in the xbasic function so that when you come back you know what you did. otherwise you will forget.
            if you are not able to do post back I will post a screencast.
            thanks for reading

            gandhi

            version 11 3381 - 4096
            mysql backend
            http://www.alphawebprogramming.blogspot.com
            [email protected]
            Skype:[email protected]
            1 914 924 5171

            Comment


              #7
              Re: Button to create parent record, get id and place id in child record

              Govindan,

              I like this approach, it sounds exactly like the way I have it programmed in my original program written in FMPro, but obviously the language it quite different. If you would post a screen cast it would be very much appreciated. I will surely be rewriting this for many other functions

              Thanks,
              Marc.
              Thanks,

              Marc McCall

              Version 12.3 2128 -4292
              MySQL backend

              If at first you don�t succeed, call it version 1.0

              Comment


                #8
                Re: Button to create parent record, get id and place id in child record

                take a look at this screencast:
                http://screencast.com/t/SXRwz1jd

                I am assuming you are using sql backend. you did not answer that part in my last question.
                Code:
                        dim current_id as n
                	dim account as c
                	dim dove_account as c
                	dim account_dove_account as c
                	
                	current_id = e._currentRowDataNew.id
                	account = e._currentRowDataNew.account
                	dove_account = e._currentRowDataNew.dove_account
                	account_dove_account = account+"_"+dove_account
                	
                	'add record to the second table and get the primary key
                	dim cn as sql::Connection
                	dim result as l
                	
                	result = cn.Open("::Name::Alpha_mysql")
                	if result then
                		dim sqlInsert as c
                		dim args as sql::Arguments
                		dim new_id as n
                		sqlInsert = "INSERT INTO dpmc2 (account_dove_account) VALUES (:NEWacctDoveAcct)"
                		args.add("NEWacctDoveAcct",account_dove_account)
                		result = cn.Execute(sqlInsert,args)
                			if result then
                				dim sqlSelect as c
                				sqlSelect = "SELECT LAST_INSERT_ID()"
                				result = cn.Execute(sqlSelect)
                				if result then
                					dim rs as sql::ResultSet
                					rs = cn.ResultSet
                				new_id = rs.data(1)
                				dim sqlUpdate as c
                				sqlUpdate = "UPDATE dpmc1 SET other_id = (:NewID) WHERE id = (:NEWcurrent_id)"
                				args.add("NewID",new_id)
                				args.add("NEWcurrent_id",current_id)
                				result = cn.Execute(sqlUpdate,args)
                				if result then
                					addLink = "alert('link created');"
                					else
                					addLink = "alert('could not create link');"
                				end if
                				else
                				addLink - "alert('Could not insert into the table!');"
                			end if
                		end if
                		cn.close()
                		else
                		addLink = "alert('Could not connect to database!');"
                	end if
                thanks for reading

                gandhi

                version 11 3381 - 4096
                mysql backend
                http://www.alphawebprogramming.blogspot.com
                [email protected]
                Skype:[email protected]
                1 914 924 5171

                Comment


                  #9
                  Re: Button to create parent record, get id and place id in child record

                  Originally posted by DDPMarc View Post
                  Thanks for the reply Mixter, It is going to take me a little bit to wrap my head around it. I'm finding out that AA is not as easy to use as I thought is was going to be.
                  Well it can be very easy if you use it in the way the builders are structured to be used.

                  As a lateral approach, can you apply some flexibility in your design?

                  Perhaps go through all the grid builders, etc, and see what is possible to build, and base your app more on that.

                  Let's talk less about the nitty gritty implementation, and more about what you actually are trying to achieve in the bigger picture...

                  Explain more about your data

                  I understand Customers table

                  but where does all this bit come from?

                  Account+"_"+Dove_Account

                  Where does is Account and Dove_Account come from?

                  are either of these two fields coming from the customer table?

                  I understand you want to concatenate them together and then append into Group_Accounts table, into Group_Name field.


                  Could you do the following.... (based on a few of my limited understanding assumptions)

                  in Customer grid, you already have [Account]

                  Somewhere else on the grid, either in the same row, or in a freeform area, display an unbound dropdown control (not bound to the customers table) that is fetching data for the lookup for the Dove_Account

                  So you already have your two pieces of data, the customer.[Account] (a row in the grid)
                  and the Dove_Account (selecting from a dropdown)

                  Now you could just but a button on the customer row.

                  on click the button, you could have some validation that a value has been entered into Dove_Account

                  and if it passes that, then let the code flow through to create and run an Append query in SQL that inserts your value into the Group_Accounts table, into Group_Name field.

                  Comment


                    #10
                    Re: Button to create parent record, get id and place id in child record

                    @Govindan ,

                    Thank you so much for the post and screen cast. That is exactly what I am trying to accomplish. I will dig into it in a little while when I'm free'd up.

                    @Mixter

                    All of the data for this utility program I am putting together comes from my office CRM and is being reformatted and linked to other data to be added to an eccomerce site. All of the data in my original post is from the Customer table, which I will soon be added linked Contact's table, Sub_contacts table, addresses, so that they can bee added to the website via API functions (click a button). The group_accounts is so I can put accounts (Customers) into groups, some (not many) of them share the same product catalogs. the group_accounts table is basically my join table for a many to many relationship. The concatenated group_name is used when I name their product catalog. The only products in our customers catalogs are what they are quoted. Each customer has their own price for each item.

                    I also have a master Products table I'll be adding where all of the product information is stored and linked to the custom_catalog table where the product info is linked but the customer prices are set up.

                    To answer you question Account is the Account Name. Dove_Account is the CRM Account_Id (Customer_id). This must go with the data to the website because there is another utility that downloads sales orders from the website via the API on a schedule (every 15min) and imports them into the CRM for processing by sales support, purchasing etc........

                    The concatenated Account and Dove_Account is just a naming convention I came up with so it is easy to select the catalog on the website from a list in the settings. It also makes it nice for searching situations as the id is always visible and easier to search by than just a name.



                    This is pretty much what my set up is going to look like.

                    Customers>---Group_Accounts---<Custom_Catalogs>----Products

                    Customers---<Contacts---<Sub_Contacts

                    Customers---<Addresses



                    What this utility allows me to do is export the raw data form our CRM in its format, then when I am done coding this, import it into the desired tables and automatically formats it into the format the website needs. Example1: the CRM Customer table has Name_First, Name_Last the website only has Name. Example2: The CRM address table has Name_First, Name_Last, Street1, Street1, the website has Street1, Street2, and a description field. So I build a description based with LTRIM(NAME_FIRST-" "+NAME_LAST-" "+STREET_1-"")

                    Eventually I won't have to export data from the CRM into this utility then add to the website via the API. I will have access to the CRM API and the website API so all I'll need to do is open the utility find the customer they want me to add to the website and click a few buttons and they are on the site. In the mean time I am rebuilding the current program I built with FMPro with AA as a learning project for AA as it will soon be my main programming software.
                    Thanks,

                    Marc McCall

                    Version 12.3 2128 -4292
                    MySQL backend

                    If at first you don�t succeed, call it version 1.0

                    Comment


                      #11
                      Re: Button to create parent record, get id and place id in child record

                      Ok, so I've written the code, How do I attach it to the button on the onClick?
                      Thanks,

                      Marc McCall

                      Version 12.3 2128 -4292
                      MySQL backend

                      If at first you don�t succeed, call it version 1.0

                      Comment


                        #12
                        Re: Button to create parent record, get id and place id in child record

                        I am tempted to say do a little research, but that is not polite.
                        if you watch my screencast I said on the onclick event I created an xbasic function
                        that is what you do.
                        on the onClick event of the button, click the eclipses on the right hand side, select ajax callback and javascript in the next popup, then select ajax callback, and in the next popup add your function name and create a template by clicking the links on the left hand side and copy into xbasic functions using paste method. and click and save as many times needed to get back.
                        then open the xbasic you will see the function, put the code you wrote there in between the declaration and the end.
                        descriptive? but I am not taking chances for you to miss anything.
                        thanks for reading

                        gandhi

                        version 11 3381 - 4096
                        mysql backend
                        http://www.alphawebprogramming.blogspot.com
                        [email protected]
                        Skype:[email protected]
                        1 914 924 5171

                        Comment


                          #13
                          Re: Button to create parent record, get id and place id in child record

                          I am tempted to say do a little research, but that is not polite.
                          I actually find that to be a funny statement. That's pretty much what I've spent the better part of three weeks doing, but the documentation for AA pretty much draws a high vacuum. That is a pretty sad statement!! Documentation-or-Lack-There of. I'm sure you are aware of this. You seem to have been around here for a while.

                          I don't want to sound rude either, but I hope I don't get blasted every time I ask a question.

                          In any event I appreciate the assistance.
                          Thanks,

                          Marc McCall

                          Version 12.3 2128 -4292
                          MySQL backend

                          If at first you don�t succeed, call it version 1.0

                          Comment


                            #14
                            Re: Button to create parent record, get id and place id in child record

                            Ok, so I have everything working good, and added a few more lines to it and comments and wanted to post my working code back here.

                            Code:
                            function createGroupAccount as c (e as p)
                            	
                            	'debug(1)
                            	
                            	dim customer_id as n
                            	dim account as c
                            	dim dove_account as c
                            	dim group_name as c
                            	dim id_group as n
                            	
                            	customer_id = e._currentRowDataNew.Customer_ID
                            	account = e._currentRowDataNew.Account
                            	dove_account = e._currentRowDataNew.Dove_Account
                            	id_group = e._currentRowDataNew.id_group
                            	group_name = account+"_"+dove_account
                            	
                            	
                            	'add record to the group_accounts table set group_name(concatenated   account+"_"+doveaccount)and get the new primary key to update customer record for data link
                            	
                            	dim cn as sql::Connection
                            	dim result as l
                            	
                            	result = cn.Open("::Name::evo_utility_db_connection") 'connect to database with named connection
                            	
                            	if id_group > 0  'Check to see if a group account id is present
                            		createGroupAccount = "alert ('A Group Account has already been made for this Customer')" 'if id is present show alert and end script
                            	else
                            		if result then 'if no id is present continue with function
                            			dim sqlInsert as c
                            			dim args as sql::Arguments
                            			dim group_id as n
                            			sqlInsert = "INSERT INTO group_accounts (group_name) VALUES (:NewGroup_Name)" 'add new record to group_accounts and enter account and dove_account as group name
                            			args.add("NewGroup_Name", group_name)
                            			result = cn.Execute(sqlInsert,args)
                            			if result then
                            				dim sqlSelect as c
                            				sqlSelect = "SELECT LAST_INSERT_ID()" 'get the last inserted id
                            				result = cn.Execute(sqlSelect)
                            				if result then
                            					dim rs as sql::ResultSet
                            					rs = cn.ResultSet
                            					group_id = rs.data(1)
                            					dim sqlUpdate as c
                            					sqlUpdate = "UPDATE customers SET id_group = (:NewGroup_ID) WHERE Customer_ID = (:NewCustomer_ID)" 'update customer with new group_accounts group_id in the id_goup field
                            					args.add("NewGroup_ID",group_id)
                            					args.add("NewCustomer_ID",customer_id)
                            					result = cn.Execute(sqlUpdate,args)
                            					if result then
                            						
                            						createGroupAccount = "alert('Your new Group Account was created!');"
                            					else
                            						createGroupAccount = "alert('Could not create new Group Account!');"
                            					end if
                            				else
                            					createGroupAccount - "alert('Could not update id into the Customers table!');"
                            				end if
                            			end if
                            			cn.close()
                            		else
                            			createGroupAccount = "alert('Could not connect to database!');"
                            		end if
                            	end if
                            	
                            end function
                            However I am trying to figure out how to get the detail view to update once the new group_id has been added to the id_goup field. I'll save this for a new thread.

                            Thanks...
                            Thanks,

                            Marc McCall

                            Version 12.3 2128 -4292
                            MySQL backend

                            If at first you don�t succeed, call it version 1.0

                            Comment


                              #15
                              Re: Button to create parent record, get id and place id in child record

                              nice work :)

                              Comment

                              Working...
                              X