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

JavaScript Loop through list and perform double click action.

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

    JavaScript Loop through list and perform double click action.

    Hi All,

    I have recently inherited responsibility for a rather complex web application used as part of my Business. I have a lot of experience working with MS Access including VBA and SQL but don't have any experience with JavaScript or Alpha in general.

    I have watched a lot of the online tutorials for Alpha and am getting a good understanding of the way thing work and I have started to learn the JavaScript notation also.

    I need to make a change to one of the main UX components in the project. This component consists of two lists, LIST1 and LIST5 both with detail views. Double clicking a line in LIST1 runs JavaScript code that copies information from the detail view of LIST1 (this is hidden) to LIST5, where is is visible and can be edited.

    I expected this to be a simple case of using the for loop, selecting each record (so that the detail view textboxes are populated) then running double click action. Unfortunately, I have been unable to fine the appropriate code to select each line and populate the details boxes, as if it were clicked.

    Can Anyone help?

    Code so far:

    var _List1 = {dialog.object}.getControl('LIST1');

    for(i=0; i <_List1._data.length;i++) {​

    ## UNKNOWN CODE

    {dialog.object}.runAction('PreDoubleClick');
    }

    Thank you

    Chris


    #2
    Hi Chris,
    Before I do anything stupid, D
    does list5 data become an exact
    duplicate of list1?
    Gregg
    https://paiza.io is a great site to test and share sql code

    Comment


      #3
      Hi Gregg,

      Thank you for your input.

      No it does not. Each list is bound to a different table in the SQL backend. Most are copied directly eg:

      {dialog.object}.setValueFrom('PROFILECOST',_COST1);

      but some are taken from additional text boxes on the form (these will be the same for each added line) and some are manipulated as they are transferred (dates).

      Chris

      Comment


        #4
        That just took it from a simple solution to a more complex solution.
        I have some ideas, but I would need to know more about the process
        before I can finalize them (this is for your sanity).
        Gregg
        https://paiza.io is a great site to test and share sql code

        Comment


          #5
          Hi, thank you for that. After my initial research did not turn up a way of 'clicking' on each line of the list in turn with a loop.( I assume you are telling me that this isn't really possible. ) I tried loading the data into variables then setting the List5 text boxes to the variables. This also hasn't worked but I don't know why.

          I will post the code for this below which will show the full process. The person I inherited this from had a lot of issues when he first coded this, in converting between US and UK date formats, so there is some pretty convoluted code that does this. It does work in the normal double click action though.

          I will add some further comments below also.


          //filter list 1

          {dialog.object}.getControl('LIST1').searchList({searchMode : 'auto'});

          // Configure Loop

          var _List1 = {dialog.object}.getControl('LIST1');
          var count = _List1._state.recordCount;
          count = count-1 //as list starts at 0 needs to minus 1

          var _List1 = {dialog.object}.getControl('LIST1');
          for(i=0; i < count;i++) {

          //START LOOP

          // Create a new record in list 5

          {dialog.Object}.setValue('DISSABLER',1);
          var lObj = {dialog.object}.getControl('LIST5');
          lObj.newDetailViewRecord();

          // now save

          if(lObj.selection[0] != 'undefined') {
          lObj._selectedRow = lObj.selection[0];
          }
          lObj.updateListFromUXControls();

          //Load varables from List1

          var _PTPCode = _List1.getData(i).PTPCode
          var _SPEC1_1 = _List1.getData(i).SPEC1
          var _DESCR1_1 = _List1.getData(i).DESCR1
          var _PSPCODE = _List1.getData(i).PSPCODE
          var _COPYFROM = _List1.getData(i).COPYFROM
          var _COST1 = _List1.getData(i).COST1
          var _DEFAULTKPI_1 = _List1.getData(i).DEFAULTKPI
          var _DOCID = _List1.getData(i).DOCID
          var _PTYPE = _List1.getData(i).PTYPE

          //Format Dates first (this is the odd code for the date formats but as i said it does work)

          //Sample Date

          var sampdt = {dialog.Object}.getValue('DATESAMPLE');
          var Sday = sampdt.slice(0,2)
          var Smth = sampdt.slice(3,5)
          var Syr = sampdt.slice(6)
          var slashx = "/"
          var sdatetoformat = Syr+slashx+Smth+slashx+Sday
          {dialog.object}.setValue('TEXTSAMPLED',sampdt)
          {dialog.object}.setValue('QSAMPLE',sdatetoformat)


          //Production Date

          var Prpdt = {dialog.Object}.getValue('PRODUCTION_DATE');
          var Pdayx = Prpdt.slice(0,2)
          var Pmthx = Prpdt.slice(3,5)
          var Pyrx = Prpdt.slice(6)
          var slashy = "/"
          var Pdatetofor = Pyrx+slashy+Pmthx+slashy+Pdayx
          {dialog.object}.setValue('DATEPRODUCED',Prpdt);
          {dialog.object}.setValue('EDIT_PRODDATE',Prpdt);
          {dialog.object}.setValue('QPRODUCED',Pdatetofor) // passed to qProduced in American format
          {dialog.object}.setValue('TEXTPRODUCED',Prpdt)

          //Date Started (This date is adjusted by a value that is stored in the SQL table linked to List1. )

          var pPlusDays = _List1.getdata(i).Daytest
          var UKdatestarted = {dialog.Object}.getValue('DATESTARTED');
          UKdatestarted = UKdatestarted+pPlusDays
          var STdayx = UKdatestarted.slice(0,2) //day
          var STmthx = UKdatestarted.slice(3,5) //mth
          var STyrx = UKdatestarted.slice(6) //yr
          var slashz = "/"
          var AmDateStart =STyrx+slashz+STmthx+slashz+Pdayx //year/mth/day
          {dialog.object}.setValue('QSTARTED',AmDateStart) // American
          {dialog.object}.setValue('TEXTSTARTED',UKdatestarted)

          //Transfer Data across (The sources that begin underscore are the variables above, the ones that start OpD are unlinked text boxes)

          {dialog.object}.setValueFrom('TPCODE',_PTPCode);
          {dialog.object}.setValueFrom('SPECUSED',_SPEC1_1);
          {dialog.object}.setValueFrom('DESCRIPTION','Opd_Description');
          {dialog.object}.setValueFrom('TEST',_DESCR1_1);
          {dialog.object}.setValueFrom('TESTCOPY',_DESCR1_1);
          {dialog.object}.setValueFrom('SPCODE',_PSPCODE);
          {dialog.object}.setValueFrom('PRODUCTCODE','Opd_ProductCode');
          {dialog.object}.setValueFrom('TARGETFROM',_COPYFROM);
          {dialog.object}.setValueFrom('PROFILECOST',_COST1);
          {dialog.object}.setValueFrom('BOOKEDINBY','BOOKEDBY');
          {dialog.object}.setValueFrom('PROJECTNO','Opd_ProjectNo');
          {dialog.object}.setValueFrom('BATCH','Opd_Batch');
          {dialog.object}.setValueFrom('UBORBBCODES','Opd_UseBy');
          {dialog.object}.setValueFrom('DEFAULTKPI',_DEFAULTKPI_1);
          {dialog.object}.setValueFrom('SAMPLINGGROUP',_DOCID);
          {dialog.object}.setValueFrom('ORDERNO','ORDERREF');
          {dialog.object}.setValue('WEBSTAT',"wProv");
          {dialog.object}.setValueFrom('SAMPLETYPE',_PTYPE);
          {dialog.object}.setValueFrom('SHIFT',"TIMESAMPLE");
          {dialog.object}.setValueFrom('BRAND',"Opd_Brand");
          {dialog.object}.setValueFrom('DATESAMPLES','DATESAMPLE');

          //Substitute new code for myref (This works to generate a unique ascending number with each addition)

          var vtally = {dialog.Object}.getValue('TALLY');
          vtally++;
          var Unumb = {dialog.Object}.getValue('USERNUMBER');
          {dialog.Object}.setValue('TALLY',vtally);
          if(vtally>9999){
          {dialog.Object}.setValue('TALLY',0);
          };

          var CalcRef = Unumb+"/"+vtally

          {dialog.object}.setValue('YOURREF',CalcRef);

          // now save

          var lObj = {dialog.object}.getControl('LIST5');
          if(lObj.selection[0] != 'undefined') {
          lObj._selectedRow = lObj.selection[0];
          }
          lObj.updateListFromUXControls();


          } //end loop​

          Comment


            #6
            I'm going to tackle the easiest thing first.
            The code below will convert mm/dd/yyyy to dd/mm/yyyy.
            If you want to test it without altering your code, look HERE (you can test different dates or even change the code if you want.)

            Is there any chance of you sending the UX with some sanitized (sample) data ?
            (I need to convert my viewbox skills to list)

            Let me know what you think.
            Code:
            function usTouk(usDate){
              const freshJSDateObject = new Date(usDate);
              const autoTZoffset = freshJSDateObject.getTimezoneOffset();
              let baseDate = new Date(freshJSDateObject.getTime() - (autoTZoffset * 3600 * 1000) ).toISOString().substr(0,10) ;    
              let ukDate = baseDate.replace(/-/g,'/')
              return ukDate
            }​
            ​
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              Hi Gregg,

              Thank you. That is very helpful, especially for my future work on this. I may look at implementing this in this procedure when I get the loop working but, as mentioned, this code does work anyway.

              Could you please confirm whether I am correct in thinking that the 'click' action cannot be done in a loop and if the "var _PTPCode = _List1.getData(i).PTPCode" is the correct syntax.

              I don't mind you looking at the UX itself but don't know how to send it to you.

              Comment


                #8
                In the web projects control panel, right click the UX, then choose export.
                Once I have it, I can see what's going on.
                Gregg
                https://paiza.io is a great site to test and share sql code

                Comment


                  #9
                  Hi,
                  I didn't get what you are trying to do exactly, but this a code I have that loop trough rows in one list and add it to another:
                  This is a part of a more complex code, just to give you the idea, (some variables might not be defined in the copied part)
                  how I do it :
                  I take the _data of the list which contains the data in the list and loop through it. (var lObj = {dialog.object}.getControl('LSTITEMS'); and lObj._data.)
                  then for each record, I use the addTableRow method of the list to add the record,

                  Using the normal add details view then updating the textboxes and then save details view should work, but with this way you have more control over the data.
                  also keep in mind javascript is asynchronous so you might sometimes need to add a timeout, before saving.

                  I hope this help, (I can clean the code more if you are interested in this method).



                  ***CODE***
                  var lObj = {dialog.object}.getControl('LSTITEMS');

                  var i;
                  for (i = 0; i < lObj._data.length; i++) {
                  mLstid = lObj._data[i].id;
                  mFreeProdid = lObj._data[i].bonusitem;

                  mQty = lObj._data[i].qty;
                  if(mQty === null) mQty = '' ;

                  mBonus = lObj._data[i].bonus;
                  if(mBonus === null) mBonus = '' ;

                  mTotq = Number(mBonus) + Number(mQty)
                  if(mTotq>0){

                  if(mFreeProdid === null) mFreeProdid="";
                  mProdid = lObj._data[i].id;
                  if(mProdid === null) mProdid="";


                  mProductCode = '';
                  mDescription = lObj._data[i].description;
                  if(mDescription === null) mDescription = '' ;
                  mImage = lObj._data[i].ItemImage;
                  if(mImage === null) mImage = '' ;
                  mPrice = lObj._data[i].price ;
                  if(mPrice===null) mPrice='' ;
                  mUnitPrice = lObj._data[i].price;
                  if(mUnitPrice === null) mUnitPrice='' ;

                  mDiscount = lObj._data[i].discount;
                  if(mDiscount === null) mDiscount='' ;
                  mVat = lObj._data[i].tva;
                  if(mVat===null) mVat='';

                  var listObj = {dialog.object}.getControl('LSTSAMPLES');
                  var data = {prodid: mProdid, visitid: mVisitid, qty: mQty, proddesc: mDescription, prodimg: mImage,company_id: mCmpId} ;
                  listObj.addTableRow(data);

                  Comment


                    #10
                    Originally posted by madtowng View Post
                    I'm going to tackle the easiest thing first.
                    The code below will convert mm/dd/yyyy to dd/mm/yyyy.
                    If you want to test it without altering your code, look HERE (you can test different dates or even change the code if you want.)

                    Is there any chance of you sending the UX with some sanitized (sample) data ?
                    (I need to convert my viewbox skills to list)

                    Let me know what you think.
                    Code:
                    function usTouk(usDate){
                    const freshJSDateObject = new Date(usDate);
                    const autoTZoffset = freshJSDateObject.getTimezoneOffset();
                    let baseDate = new Date(freshJSDateObject.getTime() - (autoTZoffset * 3600 * 1000) ).toISOString().substr(0,10) ;
                    let ukDate = baseDate.replace(/-/g,'/')
                    return ukDate
                    }​
                    ​
                    Thanks, I am saving this for future use.
                    Each time I need to convert a date from US to UK format I go trough different acrobacy :)

                    Comment


                      #11
                      Hi Paul,

                      If you check the link, there's another version of the function that converts mm/dd/yyyy to dd/mm/yyyy.
                      Gregg
                      https://paiza.io is a great site to test and share sql code

                      Comment

                      Working...
                      X