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

Moving items from one List Control to another to avoid duplicates in the

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

  • Moving items from one List Control to another to avoid duplicates in the

    I have two list controls in a UX component and I am using the 'Select List Action' and the 'Move Selected rows from one list to another' option..,.

    I want to avoid having duplicates in the 'receiving' list control..

    {dialog.object}._listMoveCurrentSelection('QUESTIONS','SANDBOX');

  • #2
    Re: Moving items from one List Control to another to avoid duplicates in the

    If it can be avoided, I wouldn't allow an opportunity to duplicate a target row. If it's a long target list then how will the user know, other than being told after the fact, they they're trying to add a row that already exists. The first time that's ok... the 2nd time it gets tired real fast.

    It's all about user experience so why frustrate the user. Filter the first list. Only put stuff in the Questions List that do not already exist in the Sandbox List. From there, you're "moving" so the Questions list is being reduced.

    Maybe your question is... how do I filter the Questions List to include rows that do not exist in the Sandbox list?

    However, if you really, really want to show everything in the Questions List... here's how you can avoid duplicates.

    Attached is altered version of Selwyn's excellent "Cool stuff you can do with List Controls" UX. The only change is in the "move the selected row" button.
    Here's a quick video... http://www.youtube.com/watch?v=3WWWaCSIWQA

    In this button we now have this code (the original action is commented out)...

    Here we grab the target list data
    create an array of keys (I'm using Lastname, which isn't a good example, so use a real unique key)
    Then grab the "key" value of the row you're moving from the source
    Now test to see if the source "key" is in the new Array we created. If so... a duplicate. If not, move it.

    There are so many ways of doing this. You could also loop through the Target data object looking for the Source key. Either way you're doing a bit of looping.

    Code:
    var ltObj = {dialog.Object}.getControl('listTarget');
    
    var ltData = ltObj._data;
    
    var lookup = {};
    for (var i = 0, len = ltData.length; i < len; i++) {
        lookup[ltData[i].Lastname] = ltData[i];
    }
    
    var sourceKey = {dialog.Object}.getValue('list::listSource::Lastname');
    
    if (lookup[sourceKey]){
    	alert('Record already exists');
    }else{
    	{dialog.object}._listMoveCurrentSelection("listSource","listTarget");
    }
    Attached Files

    Comment


    • #3
      Re: Moving items from one List Control to another to avoid duplicates in the

      Thank you...
      Because of the issue you mentioned wrt the 'annoying' alerts I thought a better solution would be to is simply scroll to the 'duplicate' record in the Target list .. So using the example...
      I replaced the alert with a scrollToItem i.e. ...

      ltObj.scrollToItem(sourceKey);

      But.... This does not seem to work properly ...
      There is a comment in a forum that this command does not work according to the example in Alpha you have to use

      {dialog.Object}.setValue('listTarget',sourceKey)

      .. but I cannot find any combination of either that works!! Do you know what the correct syntax would be when a duplicate is found in the target list to scroll to the duplicate ...

      Comment


      • #4
        Re: Moving items from one List Control to another to avoid duplicates in the

        When you scroll to that row in the list... what is the user going to do once they get there. Is there a purpose for getting there? Are they going to tap on that row and do something? Or are you just showing them that the row is already in the list?

        Comment


        • #5
          Re: Moving items from one List Control to another to avoid duplicates in the

          When an item is selected in the 'Target' list it would effectively open an 'editor' ... I was going to put a couple of text boxes etc... such that when an item is selected in the target list the user would enter details appropriate to that target list item.

          Comment


          • #6
            Re: Moving items from one List Control to another to avoid duplicates in the

            Sorry for reviving an old thread, I have a need that is the same as this post but uses a multi-select list for tech assignments. I have 2 lists (list1 and list2). When the user clicks a record from list1 a check mark is added and the data is copied to list 2 using another piece of javascript I found on the forums.

            Code to copy list1 data to list2 data
            Code:
            var listObj = {dialog.object}.getControl('list1');
            	var listCnt = listerObj.selection.length;
            	var i;
            
            for (i = 0; i < listCnt; i++) {
            	var fn = listerObj.selectionData[i].Firstname;
            	var ln = listerObj.selectionData[i].Lastname;
            	var ci = listerObj.selectionData[i].City;
            }
            
            var list2Obj = {dialog.object}.getControl('list2');
            var _d = [{Firstname: fn, Lastname: ln, City: ci}]
            listObj.appendRows(_d);
            Code to test for duplicates
            Code:
            var ltObj = {dialog.Object}.getControl('listTarget');
            
            var ltData = ltObj._data;
            
            var lookup = {};
            for (var i = 0, len = ltData.length; i < len; i++) {
                lookup[ltData[i].Lastname] = ltData[i];
            }
            
            var sourceKey = {dialog.Object}.getValue('list::listSource::Lastname');
            
            if (lookup[sourceKey]){
            	alert('Record already exists');
                    alert(sourceKey);
                    //Insert .removeRows method for list2
            }else{
            	//Insert Code to copy list1 record to list2
            }
            Since there is no deselect event for a list control, I used Davids code to test if data in list1 exists in list 2. If there is a duplicate, i need the record removed from list2 else add the record. The issue i ran into with the aboove code is with the "source key". When deselecting the record the source key does not get the value of the record that is duplicate. I added an alert to the if statment and it returns the same value of the first record no matter what record I deselect.

            Can anyone point me in the right direction to get this working? Let me know if it would help if I upload a test component.

            Thanks!

            Comment


            • #7
              Re: Moving items from one List Control to another to avoid duplicates in the

              I believe a common theme in this thread is letting do things that need to be fixed. Why would you show a user a List of Source items that are duplicates of Target Items and then have to clean up after the user has selected a duplicate. Whatever is in the Target List should not be in the Source List.

              At the very least, don't copy it, test it, and then delete it. When the user starts the copy process, check for duplicates at that time... and don't copy anything that is a duplicate... then let the user know that they selected 4 rows... 2 of which were duplicates... so only 2 were copied.

              Comment


              • #8
                Re: Moving items from one List Control to another to avoid duplicates in the

                Hi David, thank you for the response. Providing a little background may help explain why I want to accomplish this.

                I'm working on a mobile app, within my app I have a store listing. the user selects the store from a list that changes to another panel with a user list. I need to assign users to the store. Each store can have one or more users assigned to it. By using a list control i am able to multi-select specific records(users), or if the the app PM selects the wrong record(user) they can remove it from list 2. Once the PM is satisfied with their selection, I will the submit to the database with the storeId. I will then beable to filter stores by the logged in user of the app in other components.

                The goal is to hide list 2, to provide a cleaner interface and only display list 1's users to select from. I need to copy list 1 user values to list 2. If the PM unchecks (deselects) a user from list 1 I need it to be removed from list 2. The problem I am running into is when the PM unchecks a user from list 1, I get a blank value and unable to use it to loop through list 2 to find the row to remove.

                Your example code works great if it is setup as a single click list. But I am using a multi-select list.

                I have made some progress by looping through list 1's selected users and pushing them to an array. I am working on list 2's array, and will then compare the array's to find the missing value, which will then be used to remove it from list 2.

                Comment


                • #9
                  Re: Moving items from one List Control to another to avoid duplicates in the

                  What's the reason for List2? If you're selecting multiple users from List1, why bother adding them to List2 if List2 is hidden. Why not just process the selections from List1 - submitting those to your database?

                  Comment


                  • #10
                    Re: Moving items from one List Control to another to avoid duplicates in the

                    I hate to say it, but that solution did not even cross my mind. So I could write an Xbasic function to submit back to my table, by using the .selectionData[i] and loop through all selected records? Would you know of any videos or links that demonstrate this?

                    Comment


                    • #11
                      Re: Moving items from one List Control to another to avoid duplicates in the

                      There are a lot of gems in the UX Method Examples. One such is the code example for the .getListData() method. This code takes all data from a List control and processes it. Here is an exact copy of the example code...

                      Code:
                      //Submit data in a List to the server in an Ajax callback
                      var data = {dialog.object}.getListData('LIST1');
                      var dataJSON = JSON.stringify(data);
                      //urlencode the JSON data so it can be submitted as part of the Ajax callback
                      var _dataToSubmit = A5.ajax.buildURLParam('_listData',dataJSON);
                      //make a callback. 'xb' is the Xbasic function that handles the callback.
                      {dialog.object}.ajaxCallback('','','xb','',_dataToSubmit);
                      //in the xbasic function you will be able to refer to e._listData. This will have the List data in its 
                      //stringified format. Your xbasic can do this to get an Xbasic array:
                      //dim p as p
                      //p = json_parse(e._listData)
                      Now... you don't want to process all the List data... just the selected data... so we change things a bit...

                      Code:
                      lObj = {dialog.Object}.getControl('LIST1');
                      var selectedData = lObj.selectionData;
                      var dataJSON = JSON.stringify(selectedData);
                      var _dataToSubmit = A5.ajax.buildURLParam('_selectedData',dataJSON);
                      {dialog.Object}.ajaxCallback('','','processListData','',_dataToSubmit);
                      And then... in your XBasic function, processListData, you access the "additional data"...

                      Code:
                      dim processData as p
                      processData = json_parse(e._selectedData)

                      Comment


                      • #12
                        Re: Moving items from one List Control to another to avoid duplicates in the

                        David, Thank you. Through other threads that I found I was able to get the Xbasic function to instert records into my table. The code should look familiar since you wrote it. Everything works correctly except that Xbasic function runs a 2nd time. When the Xbasic tries to run a 2nd time "e._selectedData" errors out with "Property not found". I am assuming I get this error because e._selectedData is empty. I recreated my test component to clean it up but still get the error. If you have the time, could you take a look?

                        Javascript function:
                        Code:
                        function myListData(){
                        //Submit data in a List to the server in an Ajax callbac
                        var lstObj = {dialog.Object}.getControl('list1');
                        var selectedData = lstObj.selectionData;
                        var dataJSON = JSON.stringify(selectedData);
                        //urlencode the JSON data so it can be submitted as part of the Ajax callback
                        var _dataToSubmit = A5.ajax.buildURLParam('_selectedData',dataJSON);
                        //make a callback. 'xb' is the Xbasic function that handles the callback.
                        {dialog.object}.ajaxCallback('','','xb','',_dataToSubmit);
                        
                        }
                        Xbasic function:
                        Code:
                        function xb as c (e as p)
                        
                        debug(1)
                        
                        'here is the array of JSON Objects you say you already have
                        dim myJSON as c  
                        dim arr[0] as p 
                        a5_JSON_PopulateArray(arr,e._selectedData)
                        'Now you have your Array of JSON Object inside an XBasic Array
                        
                        delete cn
                        'Connect to a SQL database
                        dim cn as SQL::Connection
                        dim flag as L 
                        flag = cn.open("::Name::ASTNewStore")
                        if flag = .f. then 
                        	ui_msg_box("Error",cn.callresult.text)
                        	stop
                        end if 
                        
                        
                        
                        if flag then
                        
                        	dim p as p
                        	dim replaceArray as p
                        
                        
                        
                           'because the data is in an XBasic array, we can use that for a loop for each record update
                        	for i = 1 to arr.size()
                        
                        sql_update = <<%txt%
                        INSERT INTO people (Firstname, Lastname, City, State)
                        VALUES ('p.Firstname', 'p.Lastname', 'p.City', 'p.State');
                        %txt%
                             
                             'the following creates a pointer array and assigns the current element of our data array to it.  Then we use replace_varibles... to set up the update sql statement.
                        		replaceArray = arr[i]
                        		sql_update = replace_variables_in_string(sql_update, replaceArray, "p")
                        	
                        		flag = cn.Execute(sql_update)
                        		if flag then
                        			'nothing else to do
                        		else
                        			'there was an error - close the connection and exit
                        			cn.Close()
                        			dim msg as c 
                        			msg = "Could not execute the query. Error reported was: " + cn.CallResult.text
                        			msg = js_escape(msg)
                        			dim jscmd as c 
                        			jscmd = "alert('" + msg + "');"
                        			ProcessJSON = jscmd
                        		end if  
                        		
                        	next i		
                                cn.close()
                        
                        else
                        	'there was an error - close the connection and exit
                        	dim msg as c 
                        	msg = "Could not open the connection. Error reported was: " + cn.CallResult.text
                        	msg = js_escape(msg)
                        	dim jscmd as c 
                        	jscmd = "alert('" + msg + "');"
                        	ProcessJSON = jscmd
                        end if
                        
                        end function
                        Thanks again David, you have been a huge help!

                        SubmitCustomListDemo.zip

                        Comment


                        • #13
                          Re: Moving items from one List Control to another to avoid duplicates in the

                          This is because your "Submit List" button is calling your XBasic function directly. You need to call your Javascript function which, in turn, calls your XBasic function.

                          Get into your button click event and delete the action there. Then choose Text mode and type... myListData();

                          Now, myListData() will be called when the button is clicked.

                          For your XBasic function, you don't want to use ui_msg_box() - that's a desktop message function. Instead use A5.msgBox.show() or Javascript's alert(). The doc on A5.msgBox.show() is here... http://documentation.alphasoftware.c...sgBox/show.xml

                          You don't want to use Stop either... use end or end function.

                          Also, regarding a message sent back to the client... or anything sent back to the client... your XBasic function can return client-side code to execute. To do this you must assign this client-side code to the XBasic function name. e.g.

                          Finally, if you're working with a small number of rows, it's probably better to build a "Values" Insert rather than a single row loop Insert. You still loop through the rows but you're building code that will Insert all rows with one SQL call. I'll have a look for this code and post it.

                          Code:
                          if flag = .f. then 
                          	'ui_msg_box("Error",cn.callresult.text)
                          	myxb = "A5.msgBox.show('Error','" + js_escape(cn.callresult.text) + "','o');"
                          	end
                          end if
                          Last edited by Davidk; 03-20-2017, 11:14 AM.

                          Comment


                          • #14
                            Re: Moving items from one List Control to another to avoid duplicates in the

                            David, this is great! I have made changes to the button and the error has gone away. I have also added the a5.msgBox and tested the errors messages. This will also come in handy as I expand the code to provide a "review prompt" that will be presented to the end user before insertion. I will search the forums to see how I can create a "Values" insert, which will be much more efficent since this is a mobile app, I want one connection to the server to add all the rows instead of multiple.

                            I can't thank you enough for the help on this David.

                            Comment

                            Working...
                            X