RockU Execute Command

You are here:

Execute Command

Presenter: Jon Edmiston Length: 3:52

 
The following Lava code examples are used in this video:

{% execute %}
  return "Hello World!";
{% endexecute %}
{% execute %}
  return "Hello {{ Person.FullName }}!";
{% endexecute %}
{% capture personScriptResults %}
    {% execute %}
        return "{{ Person.FullName }}";
    {% endexecute %}
{% endcapture %}

Hello {{ personScriptResults }}
{% execute import:'System.Text,RestSharp,Newtonsoft.Json,Newtonsoft.Json.Linq' %}
    StringBuilder sb = new StringBuilder();
    sb.Append("<ul>");

    var client = new RestClient( "https://api.github.com" );
    var request = new RestRequest("repos/SparkDevNetwork/Rock/commits", Method.GET);
    IRestResponse response = client.Execute(request);
    JArray commitArray = JArray.Parse(response.Content);
    foreach( JObject commitObj in commitArray )
    {
        dynamic commit = commitObj["commit"];
sb.AppendFormat( "<li>{0} - {1}</li>", commit.message, commit.author.name ); } sb.Append("</ul>"); return sb.ToString(); {% endexecute %}
{% execute type:'class' %}

  using Rock;
  using Rock.Data;
  using Rock.Model;
    
  public class MyScript 
  {
    public string Execute() {
      using(RockContext rockContext = new RockContext()) {
        var person = new PersonService(rockContext).Get({{ CurrentPerson.Id }});
        return person.FullName;
      }
    }
  }

{% endexecute %}