Iron Speed Technical Forums
Register Latest Topics
 
 
 


Reply
  Author   Comment  
minu

Registered:
Posts: 15
Reply with quote  #1 
I want to avoid entering duplicate values in my application.If entering duplicate value a message box should shown..how wil i achieve it..


thanks in advance
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,954
Reply with quote  #2 
You may use Code Customization Wizard (CCW) - "Check If Record Already Exists Before Saving Data".

Cheers,
Jimi J

__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

annaedson

Registered:
Posts: 6
Reply with quote  #3 

I check for duplicates, but I want a popup message to display to the user about the duplicate.

 

I had this working in 8.0.2 by adding the message as follows:

Me.Page.RegisterAlert(Me.Country_Code.Text.ToString, msg, True)

 

This does not work in 9.0 - what would be the alternative code to accomplish the same goal?

akeshgupta

Avatar / Picture

Iron Speed MVP
Design, Develop & Deliver

Registered:
Posts: 1,095
Reply with quote  #4 

How did you implement it in 8.0.2 so that we can try it on 9.0?


__________________
Akesh Gupta
Light Speed Solutions, LLC.
If I rest, I will rust !   Let's share the knowledge !
annaedson

Registered:
Posts: 6
Reply with quote  #5 

This is what i did:

 

In my AddCountries.Controls.vb I added:

 

#Region "Check for Duplicate Country Code"

        '''


        ''' This sub is called when a record is getting saved. Call MyBase.SaveData()
        ''' only if duplicate record is not present in the database.
        '''

        '''

        Public Overrides Sub SaveData()
            Dim whereStr As String = CountriesTable.Country_Code.UniqueName & " = '" & Me.Country_Code.Text & "'"

            ' Check if record already exists before saving.
            Dim recctr As Integer = CountriesTable.GetRecordCount(whereStr)

            If recctr >= 1 Then

                ' If record exists, do not save the record
                Dim msg As String = "'" & Me.Country_Code.Text.ToString & "' " & EvaluateFormula("Resource(""ErrupRow"")")
                Me.Page.RegisterAlert("Unique", msg, True)
            Else

                ' Save the record if it does not exists
                MyBase.SaveData()
            End If

        End Sub

#End Region

 

In the App_Code\Shared\BaseApplicationPage.vb I added the following custom code:

 

#Region "acigCustom to allow Alerts to show when source page redirects"
        Public Sub RegisterAlert(ByVal key As String, ByVal msg As String, ByVal roaming As Boolean)
            If Not roaming Then
                MiscUtils.RegisterJScriptAlert(Me, key, msg)
            Else
                Dim AlertQueue As Hashtable = TryCast(Me.Session("AlertQueue"), Hashtable)
                If AlertQueue Is Nothing Then
                    AlertQueue = New Hashtable()
                    Me.Session("AlertQueue") = AlertQueue
                End If
                AlertQueue.Add(key, msg)

            End If
        End Sub
#End Region

annaedson

Registered:
Posts: 6
Reply with quote  #6 

I'm such a dummie. I just realized that I had made a type in the code in the App_Code\Shared\BaseApplicationPage.vb.

 

It is working - sorry for the bad post.

JBEMETO

Registered:
Posts: 160
Reply with quote  #7 
Hello Cant ISD do this at properties level for such exceptions. The code seems to long! Where else can we implement catch exceptions!!!!
__________________
JBEMETO
joetatarian

Registered:
Posts: 6
Reply with quote  #8 

Dears, I am having the same issue and I am unable to get the correct message, I logged a support case and I got ISD response which was not the answer, i was asked to add in the Validate When - Saving record the following; all I wanted to test here is not to have a duplicate phone number as a simple test

= IF(IsNull(GetColumnValues("Contact", "Phone", "field='" + ContactRecordControl.Phone.Text + "'")), "", "Phone cannot be duplicate")

with this no matter what I do, add do not add, blank no blank, duplicate or other value the message comes up and cannot continue.

Kindly help...
Joe

 

 


__________________
Joe Tatarian
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,954
Reply with quote  #9 
Joe,

If the Phone is set as unique index in the Database you can try using GetColumnValue instead. 

Another best way to prevent duplicate is validation through the business layer.
ref: http://sjc.ironspeed.com/post/keeping-business-strictly-business-%E2%80%93-validation-in-the-business-layer-4910194

Cheers,
Jimi j

__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

joetatarian

Registered:
Posts: 6
Reply with quote  #10 
Hi Jim

I guess I am asking the wrong question.

Simply my issue is the ISD default message when I enter a duplicate value; 

"Unable to update record. The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."


ISD default message so confusing for user, simply all I am asking is to change the message for example to "Duplicate Customer PO Number... please try again bla bla bla....." 

I have looked at the link and the document you provide and sadly it does not help at all, as none of what in the document exist in my project ISD 9.2

I have logged a case for this simple query which should have been something so simple, yet I spend so many hours and days, as well as asking for simple direct support to the point and still nothing...

Please advise
Joe


__________________
Joe Tatarian
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,954
Reply with quote  #11 
The main idea here is to prevent the final saving action reaching the database. That's the reason why we need to anticipate by checking if the same data already exists, then abort and inform the user via custom message. There is no other way - built in to do this feature.  

Jimi J

__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.

Download Iron Speed Designer

Terms of Service Privacy Statement