Hi ,
I need to update one particular record in found-set.
Please help me how to do it…
Hi ,
I need to update one particular record in found-set.
Please help me how to do it…
Please reply
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 ?
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
mithelash.c:
Hi roclasi,
You can call me Robert
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:
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:
// 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.
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.
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
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)
// 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);
}
pls help out
Please anyone help me.
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
Pls anyone help with this
OMG no one is helping me
(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:
// 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.
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 …I created the new records and update the value of records by myself
happy to say this robert
Regards
Mithe
Hi Mithe,
(good to know a name instead of a cryptic username )
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
…I created the new records and update the value of records by myself
happy to say this robert
That is very good to hear! thumbs up
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
Hi Mithe,
You could always contact MindFireSolutions.
They are in a timezone near you (North, East and South of India).
Hope this helps.
And Mindfire has some very smart Servoy guys!