Global Code

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
crash
User
Posts: 148

Global Code

Post 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


MichaelG
User
Posts: 1095

Post by MichaelG »

The new function must conform to C# syntax. For example:

public static string MyFunction() {
  return "MyValue";
}

crash
User
Posts: 148

Post 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


MichaelG
User
Posts: 1095

Post by MichaelG »

Try StdCurrentDateTime() instead of CurrentDateTime()

Do not use a function name which is same as your field name.


crash
User
Posts: 148

Post 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]


MichaelG
User
Posts: 1095

Post 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.


crash
User
Posts: 148

Post 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


crash
User
Posts: 148

Post by crash »

I have figured this out.

Correct code is
public static string email() {
return Convert.ToString(CurrentUserInfo("Surname"));
}


Post Reply