Page 1 of 1
Global Code
Posted: Wed Apr 27, 2022 5:00 am
by crash
I'm trying to to use autoupdate in global code.
I have setup a field called <Name>
Can anyone hlep me modify this code to auto-update to automatically input the <name>
I have already setup in the advanced settings.
Current helpfile content for global code:
public class MyExportExcel : ExportExcel {
// Override exportTableheader()
public override void ExportTableHeader() {
Text += "<div>" + Table.Caption + "</div>"; // Add table caption
base.ExportTableHeader(); // Call the parent method
}
}
Many thanks
Re: Global Code
Posted: Wed Apr 27, 2022 7:58 am
by MichaelG
The new function must conform to C# syntax. For example:
public static string MyFunction() {
return "MyValue";
}
Re: Global Code
Posted: Thu Apr 28, 2022 4:55 am
by crash
Thanks I've inserted the field I'm trying to auto-update in my advanced settings ....CurrentDateTime(),First_Name
The field is First_Name
And my code in Global code is
public static string First_Name() {
return "First_Name";
}
I then get this entry in my auto-update field
AspNetMaker2021.Models.****+DbField`1[System.Data.SqlDbType]
Is there something wrong with my code?
Any help thanks
Re: Global Code
Posted: Thu Apr 28, 2022 6:52 am
by MichaelG
Try StdCurrentDateTime() instead of CurrentDateTime()
Do not use a function name which is same as your field name.
Re: Global Code
Posted: Fri Apr 29, 2022 5:59 am
by crash
I'm only showing the CurrentDateTime() as a copy from the advanced settings... the field I've added is First_Name
I have tried putting it in another field...I'm still getting auto-update of the following then entered into the field I want the update to go to
AspNetMaker2021.Models.****+DbField`1[System.Data.SqlDbType]
Re: Global Code
Posted: Fri Apr 29, 2022 7:37 am
by MichaelG
Are you talking about "Auto-Update Value" in field setup in the following article?
https://aspnetmaker.dev/docs/#/fieldsetup.html
If yes, just select the Auto-Update Value in the field setup. If there is any error, show your table schema, problem field and the field setting.
If not, explain more clearly what you are trying to do.
Re: Global Code
Posted: Tue Jun 28, 2022 5:14 am
by crash
I'm still struggling to get this right.
I've tried using currentuserinfo.surname
My code is in Global code is
public static string PSurname() {
return "Surname";
}
In advanced settings in autoupdate I've added PSurname()
When I add it just adds the word surname..
I've checked all help files
Can anyone help with the correct code to place in Global Code.
Thanks
Re: Global Code
Posted: Tue Jun 28, 2022 5:21 am
by crash
I have figured this out.
Correct code is
public static string email() {
return Convert.ToString(CurrentUserInfo("Surname"));
}