Hot Topic (More than 10 Replies) Unique only if criteria is met (Read 1841 times)
debmckee
Full Member
***
Offline



Posts: 123
Joined: Oct 5th, 2011
Unique only if criteria is met
Feb 1st, 2012 at 9:09pm
Print Post Print Post  
Is there a way to program that a le (lotNo) is unique only if a different le (type) has a certain value? Or to let me know if it is the same based on certain criteria?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #1 - Feb 1st, 2012 at 9:24pm
Print Post Print Post  
You can. But it will take a bit of thought. Because your user has a mouse, there is no (good) way to determine the order in which they fill in the elements. So if element A is dependant on the value in element B and they fill in element A first... You may have to disable element A entriely, hide it or make it read only, until after they fill in element B. But, even then, they could go back and change the value in element B, possibly making the value in element A invalid. To deal with that, you would have to clear element A if they change element B, or at least check to make sure the two values are in concert. If they are not, maybe on form exit, disallow them from saving the invalid data and throw some sort of error, so the user can remedy the situation.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #2 - Feb 1st, 2012 at 10:04pm
Print Post Print Post  
If you merely want to check if an element is unique based on the value in an another element (without worrying about other factors), you can use an if statement on the value in the other element and put a @IsUnique call or one of the "X" commands (XLookup, XResultSet, etc) inside the curly braces for the if-statement - to look up whther the current value is unique.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
debmckee
Full Member
***
Offline



Posts: 123
Joined: Oct 5th, 2011
Re: Unique only if criteria is met
Reply #3 - Feb 3rd, 2012 at 6:55pm
Print Post Print Post  
Thank you for your response.........but I am not savy enough to implement it without help!
I tried the following:


if transaction type = "receipt" and @isunique(lotNo,"") =0

{

@msgbox("Lot Number is not unique", "","")


}

But I don't quite understand the @isunique command. I don't understand the key.  In the maual it looks like you can  only enter a specific value that you are checking to see if it is unique, what I want to know if ANY value entered is unique?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #4 - Feb 3rd, 2012 at 8:26pm
Print Post Print Post  
The unique formatting is available as a static property of an element. If you want it to be dynamic, you need to check if the value in the element is unique when your other element is set to "receipt". The @IsUnique call can check that at when the user leaves the element, but before they commit the form.

The first argument to @IsUnique is the element to check. In your case this would be "lotNo." The second argument is the value to check for. Since you want to check the value currently in lotNo, this could also be lotNo. If you test this on a form that already has a committed value, it will test as non-unique because @IsUnique was designed to test values before they get used so as to prevent the use of non-unique values being committed.

In the element exit event:
Code
Select All
if(transaction = "receipt")
{
    if(@IsUnique(lotNo, lotNo) = 0)
    {
        @MsgBox("tsk tsk")
    }
}
 



This code could use a flag and maybe a NotifyForm command to prevent the record from being committed if the condition is not met. And, as I said before, you may want to revisit the condition if they go back and change "transaction".

You may want to consider using a subroutine, so that you can call that subroutine if either transacton or lotNo change.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #5 - Feb 6th, 2012 at 6:17pm
Print Post Print Post  
Deb,
I may have what might be good news your you. I checked the source and it looks like you may be able to set the field formatting to "unique" in programming by using a "3" as the argument to the ReadOnly function in SBasic. I haven't tried it yet, but it should work. You can then restore it to "0" if your condition is not met, using an "else" clause.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Unique only if criteria is met
Reply #6 - Jun 11th, 2012 at 4:42pm
Print Post Print Post  
The Cow wrote on Feb 6th, 2012 at 6:17pm:
...I checked the source and it looks like you may be able to set the field formatting to "unique" in programming by using a "3" as the argument to the ReadOnly function in SBasic...

Interesting. I just tested this, and found that it does set a field to the unique state. But, you can't detect the unique state with @ReadOnly -- it just reports "0" (writable). Which is true, because it is writable. Though, it would be better if it reported "3".

EDIT: I also checked @Attribute, and that also reports "0".
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #7 - Jun 11th, 2012 at 10:00pm
Print Post Print Post  
Carl Underwood wrote on Jun 11th, 2012 at 4:42pm:
The Cow wrote on Feb 6th, 2012 at 6:17pm:
...I checked the source and it looks like you may be able to set the field formatting to "unique" in programming by using a "3" as the argument to the ReadOnly function in SBasic...

Interesting. I just tested this, and found that it does set a field to the unique state. But, you can't detect the unique state with @ReadOnly -- it just reports "0" (writable). Which is true, because it is writable. Though, it would be better if it reported "3".

EDIT: I also checked @Attribute, and that also reports "0".


I believe the logic in the internal code is a bit like this:
Code
Select All
ReadOnly(int flag)
{
  if(flag == 3)
  {
     UniqueFlag = 1
     ReadOnlyFlag = 0;
  }
  else
  {
     ReadOnlyFlag = flag
  }
}
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Unique only if criteria is met
Reply #8 - Jun 11th, 2012 at 10:30pm
Print Post Print Post  
Well, that explains it. Thanks Mark.

Not that I need it, but just curious...
Is there a way to check the state of UniqueFlag?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #9 - Jun 12th, 2012 at 12:42pm
Print Post Print Post  
From SBasic? I don't think so.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Unique only if criteria is met
Reply #10 - Jun 12th, 2012 at 4:57pm
Print Post Print Post  
Code
Select All
if (flag == 3 



Would you please explain what does "==" means in coding?  I do use that when I want to make blank record using @XResultSetSearch ( ) but I do not know what exactly it means. Thanks.
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Unique only if criteria is met
Reply #11 - Jun 12th, 2012 at 5:23pm
Print Post Print Post  
That's not SBasic, it's a comparison syntax for many other languages (C, C++, Java, Perl, PHP, etc). In SBasic it would be written as:
Code
Select All
if flag = 3 



When you use it with XResultSetSearch, you are actually asking Sesame the same thing as if you had simply put "=" into a field (layout element) on a form in search mode. Whereas, the equal sign means find records where the field is empty (or blank). That's because the first equal sign is part of the syntax of XResultSetSearch, and the second one is your search criteria.

So...
"!Company==" will find where company equals: a blank field
"!Company=A" will find where company equals: "A"
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Unique only if criteria is met
Reply #12 - Jun 12th, 2012 at 5:27pm
Print Post Print Post  
Thanks Carl.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Unique only if criteria is met
Reply #13 - Jun 12th, 2012 at 6:00pm
Print Post Print Post  
Bharat_Naik wrote on Jun 12th, 2012 at 5:27pm:
Thanks Carl.


Mark's been writing C all day. Switching languages makes you start putting semicolons all over the place and doubling up your equal signs.  Smiley
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged