Feld editierbar oder nicht, abhängig in welchem Form Mode ich bin
Heiko Merz
Hallo,ich habe ein Barcode Feld in die Eingangsrechnung eingefügt, welches durch die Benutzer gepflegt wird.
Nun soll dieses Feld im Add-Modus editierbar sein.
Sobald der Beleg aber hinzugefügt wurde, soll das Feld in diesem Beleg nicht mehr editierbar sein.
Code sollte also folgendes machen:
Wenn (Form Mode = "ADD"), dann Testfeld.Editable = False else true.
Hat hier jemand einen Tipp ?
Gruß
Heiko
Andreas Scherer
Hi HeikoIm FormDataLoad Event prüfen ob das Formular im Add Modus ist. Wenn ja dann enable = true und sonst enable = false.
Habs nicht getestet sollte aber so möglich sein.
Gruss
Andy
Heiko Merz
Hallo, ich möchte dieses Thema nochmal aufnehmen:Ich habe das nun soweit gelöst, dass ich das Barcodefeld standardmäßig auf disabled stelle.
Es gibt nur 2 Szenarien, dass dieses Feld offen sein soll:
1. ) Im Add Modus --> Habe ich gelöst.
2.) Im OK-Modus, wenn noch nichts in dem Feld drin steht. --> Habe ich auch gelöst, ABER: Wenn ich einen bereits vorhandenen Beleg finde und das Barcodefeld ist leer, dann ist es offen. Klicke ich nun rein und gebe die erste Zahl ein, dann geht das Feld zu (enabled = false). Ich denke das der FormDataLoad Event nochmal zieht, weil beim Eingeben der ersten Zahl in den Update Modus gewechselt wird. Dann ist das Barcode Feld nicht mehr leer, also geht es zu.
--> Anmerkung: Habe gerade noch herausgefunden, dass es nicht an der Regel liegt. Es ist allgemein so: Wenn der Beleg in den Update Modus geht, dann geht das Feld Barcode zu (Enabled = false)!!!
Wir gehen nächste Woche in Live mit dem Barcode System und das ist der letzte Step, den ich lösen muss. Wäre für eine Antwort dankbar.
CoCu-Regel anbei.
Gruß
Heiko
Attachment
[url=http://www.coresystems.ch/wp-content/../wp-content/forum-file-uploads/heiko-merzjrs-de/Barcode.cocu]Barcode.cocu[/url]
Anders Olsson
Hello Heiko,I think your rule will work just fine if you don't make the field read-only by default (I tested it). You may wish to add a rule on saving the document to disable the field if the user has entered something.
Regards,
Anders
Heiko Merz
Hello Anders,Yes, I'd like to have such a rule, but sadly do not know how to do this.
If you've tested it, can you attach the rule ?
Heiko
Heiko Merz
Hey again,sorry, but I just enabled the fields and...it works... don't know why, but it looks good. So : Thank you for that hint :-)
Heiko
Heiko Merz
Nach dem Go-Live nun doch eine Einschränkung:Die Regel holt einen Wert aus einem UDF. (Barcode).
Alles klappt, nur arbeiten die User hier mit Quickfinder, und beim Öffnen eines Beleges aus dem Quickfinder zieht die Regel, bevor sie sichtbar ist.
Somit will die Regel den Wert Barcode aus dem Feld ziehen, obwohl dieses noch gar nicht da ist, und es kommt zur Fehlermeldung.
Gibt es eine Möglichkeit das zu lösen ? Bspw. am Anfang der Regel zu sagen: Warte bis das Formular geladen ist ?
Gruß
Heiko
Anders Olsson
Hello Heiko,That makes it tricker - same thing if you open the Invoice and search by doc number... Since we can't rely on the user interface, taking the data route could work. Maybe there is a better way, but this is what I can think of: In your rule, parse pVal.BusinessObjectKey and query the database for the content of the UDF. Based on the result, you can disable the field.
Regards,
Anders
Heiko Merz
Can you give me an example for "parse pVal.BusinessObjectKey and query the database for the content of the UDF", please ?I don't know how I should do that.
Thanks again.
Anders Olsson
Sure. Here's some code you can use. I realised that the DocEntry can be accessed directly though pVal.BusinessObjectKeyString. In the code (query), replace NumAtCard with the column name of your field. I used this one for testing.
const string BARCODE_UID = "NI_00011";
string tableName = string.Empty;
switch (pVal.Form.Type)
{
case "181":
tableName = "ORPC";
break;
case "141":
tableName = "OPCH";
break;
default:
return true;
}
string docEntry = pVal.BusinessObjectKeyString;
string query = string.Format("SELECT COALESCE(NumAtCard,'') FROM {0} WHERE DocEntry = {1}", tableName, docEntry);
using (System.Data.SqlClient.SqlDataReader rdr = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(query))
{
if (rdr.Read())
{
string barcode = (string) rdr[0];
if (barcode.Length > 0)
{
TextEdit.GetFromUID(pVal.Form, BARCODE_UID).Enabled = false;
}
}
}
return true;
I hope this makes sense.
Regards,
Anders
Heiko Merz
Thank you Anders, no error message when opening from Quickfinder.The only small thing: When I now open a document with quickfinder, the field is enabled, no matter of it is filled or not. When I then go to the next or previous document, it's disabled when filled and enabled when not filled.
But the first document I open is always enabled.
Heiko
0
Please sign in to leave a comment.
Comments
0 comments