Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 3 of 3

Thread: How can I delete an item in array of structure inside a table using javascript

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    104

    Default How can I delete an item in array of structure inside a table using javascript

    Hi,

    When we delete a record in javascript, I use the following code:

    var fBP = new SCFile("optbillingpoint");
    var rcFound = fBP.doSelect("id = \"" + system.vars.$id + "\"");
    if (rcFound == RC_SUCCESS) {
    fBP.doDelete();
    }

    What if I have an array of structure inside the table and I want to delete an entry inside that array. Does anyone knows the code for that?

    Would appreciate any ideas on this.


    Thanks.

  2. #2
    Junior Member
    Join Date
    Jan 2003
    Location
    Marlborough, CT
    Posts
    24

    Default

    We have an array of structures in our cm3r table. Now I am not deleting from this, but here is how I accessed the records in it via Javascript:

    cm3r = record set
    performed_on_structure is my array of structures. I am looping through each record in the array and creating a string via concatenation.

    for (var x = 0; x <= cm3r.performed_on_structure.getSize(); x++)
    {
    if (cm3r.performed_on_structure[x].device_name == null)
    {
    fileData = fileData + fileDelim;
    break;
    }
    subFileData = cm3r.number + fileDelim;
    subFileData = subFileData + cm3r.performed_on_structure[x].device_name + fileDelim;
    subFileData = subFileData + cm3r.performed_on_structure[x].start_date+fileDelim;
    subFileData = subFileData + libcm3r.performed_on_structure[x].completion_code + fileDelim;
    subFileData = subFileData + cm3r.performed_on_structure[x].stop_date + fileDelim;
    subFileData = subFileData + cm3r.performed_on_structure[x].completion_date;
    }

    You basically treat like a regular array, except you can access the fields by their actual name. I haven't tried but you may be able to use the splice() function since the object is an array (cm3r.performed_on_structure[]).

    Hope this makes sense and helps.

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    104

    Default

    Thanks for the additional info.

    For some reason, I was not getting the expected result when using splice. Maybe I'm using it in a wrong way. So, I just implemented it this way:

    I went through the list of values that I need to include and put them in a new array.

    Then I set the value of the orig array to the new array. Now, the elements that I need to remove are not included.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts