# How to update the foundset ...urgent please

**URL:** <https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506>\
**Category:** Classic Servoy\
**Created:** [July 10, 2015, 12:19pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506 "2015-07-10T12:19:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 10, 2015, 12:19pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/1 "2015-07-10T12:19:11Z")

</div>

Hi ,

I need to update one particular record in found-set.

Please help me how to do it…

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 10, 2015, 1:59pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/2 "2015-07-10T13:59:01Z")

</div>

Please reply

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 10, 2015, 3:10pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/3 "2015-07-10T15:10:51Z")

</div>

Hi

First of all welcome to the forum. I see these are your first posts.

Can you tell us what you have trouble with exactly ?

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 10, 2015, 4:17pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/4 "2015-07-10T16:17:12Z")

</div>

Hi roclasi,

I’m new to servoy…and having one problem.

For my business need …  
In short:  
I need to create the record in the db if it not present .

if its present i need to update the existing ones.

In detail.

There is 3 radio buttons yes, no ,N/A.

If i press yes, one record should created…after pressing yes if i press no or N/A ,it should updated the created record.

if(cor==‘Yes’)  
{  
var \_fsinj = databaseManager.getFoundSet(‘practice’, ‘me\_inj’)  
\_fsinj.find()  
\_fsinj.fk\_med\_inf = medcoid  
\_fsinj.secondary\_ds =1  
var \_success = \_fsinj.search()

//If record doesnt exist then create it!  
if (!\_success) {  
\_fsinj.newRecord()  
\_fsinj.fk\_med\_inf =medid  
\_fsinj.secondary\_ds = 1  
\_fsinj.primary\_ds =2

}

\_fsinj.primary\_ds = 2

databaseManager.saveData()

}

if(cor==‘No’)  
{  
var \_fsinj = databaseManager.getFoundSet(‘practice’, ‘me\_inj’)  
\_fsinj.find()  
\_fsinj.fk\_med\_inf = medcoid  
\_fsinj.secondary\_ds =1  
var \_success = \_fsinj.search()

//If record doesnt exist then create it!  
if (!\_success) {  
\_fsinj.newRecord()  
\_fsinj.fk\_med\_inf =medid  
\_fsinj.secondary\_ds = 1  
\_fsinj.primary\_ds =1

}

\_fsinj.primary\_ds = 2

databaseManager.saveData()

}

\_fsinjury.primary\_diagnosis = 1

databaseManager.saveData()  
}  
if(cor==‘N/R’)  
{

var \_fsinj = databaseManager.getFoundSet(‘practice’, ‘me\_inj’)  
\_fsinj.find()  
\_fsinj.fk\_med\_inf = medcoid  
\_fsinj.secondary\_ds =1  
var \_success = \_fsinj.search()

//If record doesnt exist then create it!  
if (!\_success) {  
\_fsinj.newRecord()  
\_fsinj.fk\_med\_inf =medid  
\_fsinj.secondary\_ds = 1  
\_fsinj.primary\_ds =0

}

\_fsinj.primary\_ds = 2

databaseManager.saveData()

}  
}

its always creating record, not checking if the record is present r not…

Pls help out

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 10, 2015, 8:50pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/5 "2015-07-10T20:50:41Z")

</div>

> mithelash.c:  
> Hi roclasi,

You can call me Robert ![:)]( "Smile")

Is this the full code you use in a method? Because it’s not balanced code ( there are more ‘}’ than ‘{’ ).  
Also you reference \_fsinj in most of your code but also \_fsinjury (only once).

So I commented those bits out:

```auto
if (cor == 'Yes') {
    var _fsinj = databaseManager.getFoundSet('practice', 'me_inj')
    _fsinj.find()
    _fsinj.fk_med_inf = medcoid
    _fsinj.secondary_ds = 1
    var _success = _fsinj.search()

    //If record doesnt exist then create it!
    if (!_success) {
        _fsinj.newRecord()
        _fsinj.fk_med_inf = medid
        _fsinj.secondary_ds = 1
        _fsinj.primary_ds = 2
    }

    _fsinj.primary_ds = 2
    databaseManager.saveData()
}

if (cor == 'No') {
    var _fsinj = databaseManager.getFoundSet('practice', 'me_inj')
    _fsinj.find()
    _fsinj.fk_med_inf = medcoid
    _fsinj.secondary_ds = 1
    var _success = _fsinj.search()

    //If record doesnt exist then create it!
    if (!_success) {
        _fsinj.newRecord()
        _fsinj.fk_med_inf = medid
        _fsinj.secondary_ds = 1
        _fsinj.primary_ds = 1
    }

    _fsinj.primary_ds = 2
    databaseManager.saveData()
}

// Not sure what the following does....

// _fsinjury.primary_diagnosis = 1
//
// databaseManager.saveData()
// }

if (cor == 'N/R') {
    var _fsinj = databaseManager.getFoundSet('practice', 'me_inj')
    _fsinj.find()
    _fsinj.fk_med_inf = medcoid
    _fsinj.secondary_ds = 1
    var _success = _fsinj.search()

    //If record doesnt exist then create it!
    if (!_success) {
        _fsinj.newRecord()
        _fsinj.fk_med_inf = medid
        _fsinj.secondary_ds = 1
        _fsinj.primary_ds = 0
    }

    _fsinj.primary_ds = 2
    databaseManager.saveData()
}

// Too many braces
//}

```

So looking at this I see that you don’t check if you really are able to get into find mode on that foundset. When a foundset has unsaved data it will not go into find mode, so you need to check for that.  
Also you are repeating a lot of code just to take care of 1 difference, so i simplified your code a bit:

```auto
// lets declare all used variables at the top
var _fsinj = databaseManager.getFoundSet('practice', 'me_inj');

// check if we can get into find mode
if (_fsinj.find()) {
    _fsinj.fk_med_inf = medcoid;
    _fsinj.secondary_ds = 1;

    //If record doesn't exist then create it!
    if (_fsinj.search() === 0) {
        _fsinj.newRecord();
        _fsinj.fk_med_inf = medid;
        _fsinj.secondary_ds = 1;

        if (cor === 'Yes') {
            _fsinj.primary_ds = 2;
        } else if (cor === 'No') {
            _fsinj.primary_ds = 1;
        } else if (cor === 'N/R') {
            _fsinj.primary_ds = 0;
        }
    }

    _fsinj.primary_ds = 2;
    databaseManager.saveData();
} else {
    application.output("Can't get into find mode", LOGGINGLEVEL.ERROR);
}

```

Now you can use this code and step through it in developer using the debugger to see what really is being entered in the search criteria. This way you know exactly what the search does and then can check why it doesn’t get the record it should find.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 11, 2015, 4:13am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/6 "2015-07-11T04:13:55Z")

</div>

Robert,

Another query : how to get PK for newly created record

Robert,Keep in touch will send many queries …because i’m enhancing existing application without proper knowledge.

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 11, 2015, 5:13am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/7 "2015-07-11T05:13:27Z")

</div>

Robert…some problem here.

Actually, there are 3 forms.  
A B C  
three forms should create 3 records with same fk\_med\_inf(which is PK of other table) let us say 1234.  
id fk\_med\_inf secondary\_ds primary\_ds  
1 1234 0 0/1/2(yes,no,N/A) ------This is form A .  
2 1234 1 0/1/2(yes,no,N/A)------This is form B  
3. 1234 2 0/1/2(yes,no,N/A) ------This is form C

1. In single form,how many times I press yes/no/NA only one record should available but here how many times i press yes/no/NA that much record is appearing .

below code is not finding any records.so i cant update any record…always creating one record

Expected outcome:

id fk\_med\_inf secondary\_ds primary\_ds  
1 1234 0 0/1/2(yes,no,N/A) ------This is form A .

But,Current outcome its creating new record (if we press n number of times yes/no/NA.then n number of records) not updating previous one …

id fk\_med\_inf secondary\_ds primary\_ds  
1 1234 0 0/1/2(yes,no,N/A)  
2 1234 0 0/1/2(yes,no,N/A)  
3 1234 0 0/1/2(yes,no,N/A)

```auto
// lets declare all used variables at the top
//here i'm declaration medid its pk 
var _fsinj = databaseManager.getFoundSet('practice', 'me_inj');

// check if we can get into find mode
if (_fsinj.find()) {
    _fsinj.fk_med_inf = medid;
    _fsinj.secondary_ds = 1;
//here we need to check if the record present we need to update the value based on the condition .if record is not present it should create one based on the condition yes/no/N/A
    if (_fsinj.search() === 0) {
        _fsinj.newRecord();
        _fsinj.fk_med_inf = medid;
        _fsinj.secondary_ds = 1;
if (cor === 'Yes') {
            _fsinj.primary_ds = 2;
        } else if (cor === 'No') {
            _fsinj.primary_ds = 1;
        } else if (cor === 'N/R') {
            _fsinj.primary_ds = 0;
        }
  databaseManager.saveData();
}

//if record is present update the value based on the condition.
if (cor === 'Yes') {
            _fsinj.primary_ds = 2;
        } else if (cor === 'No') {
            _fsinj.primary_ds = 1;
        } else if (cor === 'N/R') {
            _fsinj.primary_ds = 0;
        }
  databaseManager.saveData();
}
    databaseManager.saveData();
} else {
    application.output("Can't get into find mode", LOGGINGLEVEL.ERROR);
}

```

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 11, 2015, 5:47am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/8 "2015-07-11T05:47:08Z")

</div>

pls help out

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 11, 2015, 11:12am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/9 "2015-07-11T11:12:20Z")

</div>

Please anyone help me.

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 11, 2015, 2:13pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/10 "2015-07-11T14:13:41Z")

</div>

Pls anyone help…what i thought is getFoundset fetches only 200 records so search is not possible …because of no search ,no update happens.please anyone help to sort this problem

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 11, 2015, 4:31pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/11 "2015-07-11T16:31:14Z")

</div>

Pls anyone help with this

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 12, 2015, 3:49am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/12 "2015-07-12T03:49:34Z")

</div>

OMG ![:(]( "Sad") no one is helping me

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 13, 2015, 9:28am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/13 "2015-07-13T09:28:14Z")

</div>

(emphasis is mine)

> mithelash.c:  
> Robert,Keep in touch will send many queries …because i’m enhancing existing application **without proper knowledge**.

Why do you think that is a good idea?

You obviously need a lot more help than this forum can give you so I suggest you hire some help from one of the consultants here to get you and/or your project up to speed.  
As you already have noticed a forum is not the place to get immediate answers (even though sometimes you get them quick). It’s definitely not the place to **demand** answers to your questions.  
People will answer if they have the answer, if they don’t or simply don’t have the time they won’t respond. Also keep in mind that a lot of us don’t check the forum that often, especially because of weekends and/or (summer) vacations.

So, I looked at your code and you obviously copied code and made mistakes while doing that. Again your code was not balanced.  
Here is the fixed and a bit more optimized code:

```auto
// lets declare all used variables at the top
//here i'm declaration medid its pk
var _fsinj = databaseManager.getFoundSet('practice', 'me_inj');

// check if we can get into find mode
if (_fsinj.find()) {
    _fsinj.fk_med_inf = medid;
    _fsinj.secondary_ds = 1;
    //here we need to check if the record present we need to update the value based on the condition .if record is not present it should create one based on the condition yes/no/N/A
    if (_fsinj.search() === 0) {
        _fsinj.newRecord();
        _fsinj.fk_med_inf = medid;
        _fsinj.secondary_ds = 1;
    }

    //if record is present update the value based on the condition.
    if (cor === 'Yes') {
        _fsinj.primary_ds = 2;
    } else if (cor === 'No') {
        _fsinj.primary_ds = 1;
    } else if (cor === 'N/R') {
        _fsinj.primary_ds = 0;
    }
    databaseManager.saveData();
    
    // the following lines don't make much sense and were probably copied over (wrongly)
    
    //}
    // databaseManager.saveData();
    
} else {
    application.output("Can't get into find mode", LOGGINGLEVEL.ERROR);
}

```

But again, I strongly suggest you hire someone to train you or to help you with your project.

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 13, 2015, 6:27pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/14 "2015-07-13T18:27:01Z")

</div>

Hi Robert,

Your absolutely right , lack of knowledge is the worst thing in the world . I signed up Servoy university ,now watching premium videos and its helping me lot.

Apart from Servoy university videos , Can you suggest where to hire someone to train me or any on-line training is available?

Thanks for your reply…your code is very useful and its working too.

And one more good news ![:)]( "Smile") …I created the new records and update the value of records by myself ![:)]( "Smile") happy to say this robert ![:)]( "Smile")

Regards  
Mithe

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 13, 2015, 7:01pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/15 "2015-07-13T19:01:26Z")

</div>

Hi Mithe,

(good to know a name instead of a cryptic username ![;)]( "Wink") )

> mithelash.c:  
> Your absolutely right , lack of knowledge is the worst thing in the world . I signed up Servoy university ,now watching premium videos and its helping me lot.
> 
> Apart from Servoy university videos , Can you suggest where to hire someone to train me or any on-line training is available?

Servoy-U is a very good source to start with.  
As for hiring someone. You can ask on the forum here to get contacted directly by mail or DM or you can get into contact with Servoy, they can/might transfer you to a Servoy partner in your region. Doing things remotely is also an option using Skype/TeamViewer and the like but having someone in your timezone is always a plus.  
Where are you located?

> mithelash.c:  
> Thanks for your reply…your code is very useful and its working too.
> 
> And one more good news ![:)]( "Smile") …I created the new records and update the value of records by myself ![:)]( "Smile") happy to say this robert ![:)]( "Smile")

That is very good to hear! _thumbs up_ ![:D]( "Very Happy")

---

<div class="post-metadata">

**Author:** ![mithelash.c](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mithelash.c](https://forum.servoy.com/u/mithelash.c)\
**Post date:** [July 14, 2015, 3:49am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/16 "2015-07-14T03:49:09Z")

</div>

Hi Robert,

I am from Chennai,India.

I think it will be difficult to get some one in my time zone.

Anyway,its good to have ServoyU with me.

regards  
Mithe

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 14, 2015, 8:48am UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/17 "2015-07-14T08:48:44Z")

</div>

Hi Mithe,

You could always contact [MindFireSolutions](http://www.mindfiresolutions.com/contact.htm).  
They are in a timezone near you (North, East and South of India).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Jan\_Aleman](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jan\_Aleman](https://forum.servoy.com/u/Jan_Aleman)\
**Post date:** [July 14, 2015, 12:39pm UTC](https://forum.servoy.com/t/how-to-update-the-foundset-urgent-please/18506/18 "2015-07-14T12:39:35Z")

</div>

And Mindfire has some very smart Servoy guys!
