everytime I'm doing open browser, my data got duplicate

everytime I'm doing open browser, my data got duplicate

  

I tried to make an if logic so if firstname or lastname is the same in database it won't create a new data, but no success. 

anyone what's the problem here? I uploaded my oml, so anyone can look the function and what action I use there.

Hi Calvin,

I can't see oml attached, Still showing processing Upload. However, Could you please check one thing if you are using any action/button on your Data Users page make sure it is of method AjaxSumbit not Submit.


Sachin


 

Hey Calvin,

In addition to Sachin's question, what is dataUsers?  It seems to be a local variable, but when is it assigned to allow you to compare to the element from GetUsers?

Sachin Mahawar wrote:

Hi Calvin,

I can't see oml attached, Still showing processing Upload. However, Could you please check one thing if you are using any action/button on your Data Users page make sure it is of method AjaxSumbit not Submit.


Sachin


 

nope, its not everytime I click any action/button, but everytime I open DataUsers screen, the data is duplicated. And all my buttons is used ajax submit


Craig St. Jean wrote:

Hey Calvin,

In addition to Sachin's question, what is dataUsers?  It seems to be a local variable, but when is it assigned to allow you to compare to the element from GetUsers?

I used it as a source for CreateOrUpdatedataUsers


i think the problem is what I got in preparation DataUsers

if I remove the tampungUsers action, my DataUsers screen is fine, but if I remove that action, the first time I run, it won't get any data, like literally 0 data in my DataUsers screen.

Solution

Hi Calvin,


Yes the issue is in your Preparation.

You will not have any value in dataUsers when you are going inside the tampungUsers method. 

So you can not check dataUsers.First_name=GetUsers.Re... Because it will simply give you false and your data will be inseted again and again on Preparation. 

Also check whether you are passing uniqueID in CreateOrUpdate method, as if the ID is different or 0 it will simply create new DataRow everytime.

Regards,

Palak

Solution

Palak Patel wrote:

Hi Calvin,


Yes the issue is in your Preparation.

You will not have any value in dataUsers when you are going inside the tampungUsers method. 

So you can not check dataUsers.First_name=GetUsers.Re... Because it will simply give you false and your data will be inseted again and again on Preparation. 

Also check whether you are passing uniqueID in CreateOrUpdate method, as if the ID is different or 0 it will simply create new DataRow everytime.

Regards,

Palak

Im not assigning attribute Id because Im using auto number , is it wrong?

Yes Calvin,

Its wrong. Because in database if you want to update a record, you must provide ID. Then only it will update the record.
For your case, you have used CreateOrUpdate function. In this function, If you will not provide ID it will take it as NullIdentifier() and it will simply create a new row. 

Palak Patel wrote:

Yes Calvin,

Its wrong. Because in database if you want to update a record, you must provide ID. Then only it will update the record.
For your case, you have used CreateOrUpdate function. In this function, If you will not provide ID it will take it as NullIdentifier() and it will simply create a new row. 


when I tried to assign the attribute Id, I only got nullidentifier() as a suggestions.

One more thing Calvin,

By looking into your logic I think that you don't even need assign variable and if condition.

Just use like below and assign GetUsers.Response.Data.Current in Source of CreateOrUpdatedataUsers directly. You don't need a separate variable. It will automatically check if user is there in database or not. If not it will insert directly.

Calvin Adi wrote:

when I tried to assign the attribute Id, I only got nullidentifier() as a suggestions.


Yes, you don't even need that assign and if condition. Please check my previous reply. You just need a CreateOrUpdate and assign source as GetUsers.Response.Data.Current

what should I do to the attribute Id

Calvin Adi wrote:

what should I do to the attribute Id

You are not getting UserId from your web service?  In your GetUsers.Response.Data.Current?

If not, you should not compare and use directly from the web service.
Instead, check everytime whether it is available in your database or not.
Using an aggregate, check user with the same first_name and last_name exists or not.
If not, then only insert inside your database table. 


Palak Patel wrote:

Calvin Adi wrote:

what should I do to the attribute Id

You are not getting UserId from your web service?  In your GetUsers.Response.Data.Current?

If not, you should not compare and use directly from the web service.
Instead, check everytime whether it is available in your database or not.
Using an aggregate, check user with the same first_name and last_name exists or not.
If not, then only insert inside your database table. 


the datatype for Id from the API is longinteger and because I change the Id to identifier, it need identifier datatype. LongIntegerToIdentifier(Id) looks correct I think, but it makes my data can't be updated or changed.


Yes. Its the correct behaviour. Because, when you are updating data using details page, its actually updating the correct value but on list oage load its again updating records by preparation which you are getting from your API. 

So for that you need to set some column i.e. IsUpdated when its updated by details screen. 

When you fetch next tym from the API , it will only update records from API which are not updated manually. 


Cheers.

thanks, I will just make a new screen for that, thanks for the help sir

Hi Calvin,

I would suggest you to create a function(User_AlreadyExist) to check if user already exist.

Pass two input parameters let say 'first_name' and 'last_name'.

Pass one more input parameters let say 'UserIdToExclude', make sure data type should be of 'getdatauser' entity identifier.

Pass one boolean type output parameter let say 'user_exist'.

Inside that function drag your 'getdatauser' entity and in filter of this aggregate use below:

getdatauser.first_name= first_name

getdatauser.last_name=last_name

Now you use a assignment operator and assign below value to to your output parameter:

not getdatauser.List.Empty and getedatauser.List.Current.DataUser.Id <> UserIdToExclude


Drag that function in place of your if statement and loop thru first_name, last_name as input parameter to this function.

Now you put a if statement and check for : 

'User_AlreadyExists.AlreadyExists' if no create user else pass your custom message.


Aditya Gaur wrote:

Hi Calvin,

I would suggest you to create a function(User_AlreadyExist) to check if user already exist.

Pass two input parameters let say 'first_name' and 'last_name'.

Pass one more input parameters let say 'UserIdToExclude', make sure data type should be of 'getdatauser' entity identifier.

Pass one boolean type output parameter let say 'user_exist'.

Inside that function drag your 'getdatauser' entity and in filter of this aggregate use below:

getdatauser.first_name= first_name

getdatauser.last_name=last_name

Now you use a assignment operator and assign below value to to your output parameter:

not getdatauser.List.Empty and getedatauser.List.Current.DataUser.Id <> UserIdToExclude


Drag that function in place of your if statement and loop thru first_name, last_name as input parameter to this function.

Now you put a if statement and check for : 

'User_AlreadyExists.AlreadyExists' if no create user else pass your custom message.


where do I make that function?


Calvin Adi wrote:

Aditya Gaur wrote:

Hi Calvin,

I would suggest you to create a function(User_AlreadyExist) to check if user already exist.

Pass two input parameters let say 'first_name' and 'last_name'.

Pass one more input parameters let say 'UserIdToExclude', make sure data type should be of 'getdatauser' entity identifier.

Pass one boolean type output parameter let say 'user_exist'.

Inside that function drag your 'getdatauser' entity and in filter of this aggregate use below:

getdatauser.first_name= first_name

getdatauser.last_name=last_name

Now you use a assignment operator and assign below value to to your output parameter:

not getdatauser.List.Empty and getedatauser.List.Current.DataUser.Id <> UserIdToExclude


Drag that function in place of your if statement and loop thru first_name, last_name as input parameter to this function.

Now you put a if statement and check for : 

'User_AlreadyExists.AlreadyExists' if no create user else pass your custom message.


where do I make that function?


Create it as a new server action and use it in your existing functions/server action: TamPungUser