I am trying to write C# in Item saved event of Script item Code Field, as shown in the attached image.
My question is can we write C# code in this field and if it is possible what syntax should I follow?
Essentially, yes you are able to add your own custom code.
The Type
field is where you would define your using
in your class. You will want to add any additional namespaces your code needs here.
The Code
field then contains all C# code within and including the namespace
declaration. This is where you can define your properties, methods etc.
As this is a rule you are creating you need to define a Sitecore rule as follows.
namespace UserAction
{
public class NewUserAction<T> : RuleAction<T> where T : RuleContext
{
public override void Apply(T ruleContext)
{
Assert.ArgumentNotNull(ruleContext, "ruleContext");
}
}
}
In terms of syntax / guidelines you will need to adhere to standard C# synatax and follow best practices of .NET and Sitecore.
I would recommend writing the code in Visual Studio for ease of use. Once you are sure it works and compiles copy the usings
into the Type
field and the the code within the namespace
declaration and the namespace
itself into the Code
field.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.