• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

@Environment Problem

I have a form that has a button which creates a duplicate document in order to save on rekeying etc.

One of the fields is an invoice number and this need to have a letter put to the end of the number everytime this  button is pressed and a new documnet is created

I am working off Environment fields in order to create the new doc, but i can't get the InvoiceNumber Field to take on the new letter that should be assigned to it, the code i have tried is as follows:

envvar := @Environment("InvoiceNumber");
@If(envvar != ""; @SetEnvironment( "InvoiceNumber"; ""); "");
envvar;

@If(@Ends(@Environment("InvoiceNumber");"a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");@Right(@SetEnvironment("InvoiceNumber";"");7); @Right(@SetEnvironment("InvoiceNumber";"");6));  

Any help please
0
DavidAbbott
Asked:
DavidAbbott
  • 6
  • 4
  • 3
  • +1
1 Solution
 
qwaleteeCommented:
Here's your problem: you reset the environment variable before you use it!

Your second line nakes the variable blank, butthen you try to use the variable in fifth line!!
0
 
qwaleteeCommented:
envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
endsInLetter := @Ends(envVar;"a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");
sizeToGet := @If(endsInLetter;7;6)
@Right(envVar;sizeToGet)
0
 
HemanthaKumarCommented:
Here is the modified code

envvar := @Environment("InvoiceNumber");
envvar


@If(@Ends(@Environment("InvoiceNumber");"a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");@Right(@SetEnvironment("InvoiceNumber";"");7); @Right(@SetEnvironment("InvoiceNumber";"");6));  


~Hemanth
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
qwaleteeCommented:
Of course, I don't think you are really dong this the right way anyway.

1) You should use inheritance to transfer values, instead of environment vaiables

2) Where are you SETTING the value of this environment value to start with -- why would it not always be missing (blank)?

3) The whole 6 v. 7 business makes no sense to me.  Let's say the "main" invoice number is a six-digit number, and you are appending a single letter.  So, if there is NO letter on the end, you want the whole thing, and then you want to add a letter. If there IS a letter on the end, you want to take the whole thing with the letter.  At least, that's what your code says. Most likely, you want to do the opposite -- make sure you get the first 6 characters nomatter what, always dropping the last letter, then add a new letter on the end.  the new letter will depend on the previous letter -- a if there was none, b if a, c if b, etc.  Do I understand what you WANT correctly?  he code woudl eb as follows:

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
@If(@Length(enVar = 6; @Return(envVar + "a"); CONTINUE );
letters := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
base := @Left(enVar;6);
priorLetter := @Right(envVar;1);
newLetter := @Replace(priorLetter; "dummy" : letters; letters : "error- ran out of alphabet!");
base + newLetter
0
 
HemanthaKumarCommented:
I believe it is two piece of code ? Am I right ? Anyway The second line of code also has some problems

envvar := @Environment("InvoiceNumber");
envvar


@If(@Ends(@Environment("InvoiceNumber");"a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");@Right(@Environment("InvoiceNumber");7); @Right(@Environment("InvoiceNumber");6));  
(@SetEnvironment("InvoiceNumber";"");
0
 
Sjef BosmanGroupware ConsultantCommented:
You seem not to care about multiple users on multiple databases on multiple servers doing the same thing at the same time, hence creating duplicate documents (not replication conflicts). Well, that's not the issue here, is it? ;-)

Suggested ways to solve the problem, prioritized:
1. use @DbLookup to find existing documents and adapt the invoice number (if a unique key is required)
2. store the latest invoice number in the original document
3. anything else
4. ... or this ...
....
9999. use environment vars

0
 
DavidAbbottAuthor Commented:
None of the above works, i will try to make my problem a bit clearer.

The button carrys the code: (with other fields)

@Environment("InvoiceNumber"; @Text(InvoiceNumber));
@PostedCommand([FileCloseWindow]);
@PostedCommand([Compose]; ""; "Customer Log")

and the field has the code:


envvar := @Environment("InvoiceNumber");
@If(envvar != ""; @SetEnvironment( "InvoiceNumber"; ""); "");
envvar;

@If(@Ends(@Environment("InvoiceNumber");"a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");@Right(@SetEnvironment("InvoiceNumber";"");7); @Right(@SetEnvironment("InvoiceNumber";"");6));  

What i need is, if the button is pressed and the field already has an invoice number (which it would have) for a suffix of a, or if it has already a suffix of a then b and if it has already a suffix of b then c etc etc, but only one letter to be present at any time

Cheers Guys
0
 
HemanthaKumarCommented:
This will be the code to do that

envvar := @Environment("InvoiceNumber");
@If(envvar != ""; @SetEnvironment( "InvoiceNumber"; ""); "");
alphas := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
idx  := @If(@Ends(a;alphas); @member(@Right(envvar; 1); alphas); 0);
@leftback(envvar;1) + @if( idx > 0; @Subset(@Subset(alphas;idx+1);-1);  "");
0
 
qwaleteeCommented:
The code I gave earlier will do that, assuming a 6 charcater (no letter suffix) or 7 characer with one letter suffix) invoice number.

Can you confirm that invoice numbers are 6+1 character, i.e., 135791, 135791a, 135791b, etc.?

Only problem was, I had a typo, now fixed:

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
letters := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
base := @Left(envVar;6);
priorLetter := @Right(envVar;1);
newLetter := @Replace(priorLetter; "dummy" : letters; letters : "error- ran out of alphabet!");

  base + newLetter
0
 
DavidAbbottAuthor Commented:
still a problem with this,
0
 
DavidAbbottAuthor Commented:
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );

Something wrong with this line I believe
0
 
HemanthaKumarCommented:
David I recd your mail.. din't see it for past 1 week

If you want me to take a look at your form send it to me I will take a look at it. Zip if before you send with minimal design for the form to work.

0
 
qwaleteeCommented:
Change from
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
to
@If(@Length(envVar) = 6; @Return(envVar + "a"); CONTINUE );


It was the missing ) after @Length(envar
0
 
qwaleteeCommented:
(We alredy covered this in the other question)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now