Question

To Use Macros based on Two values

Hi

 

I want to change the text in printable based on the two values of printable. Please let me know if there is any way we can do that.

 

Regards

Rakshith Dheer

Like 0

Like

1 comments

To accomplish this, what I typically do is add the macro to the record Id, then in the macro use an ESQ to get the needed values and return the result. You can get the UserConnection in the macro using something like this: 

namespace Terrasoft.Configuration 
{
  using System;
  using Terrasoft.Common;
  using Terrasoft.Core;
  using Terrasoft.Core.DB;
  using Terrasoft.Core.Entities;
  using Terrasoft.Core.Packages;
  using Terrasoft.Core.Factories;
  using System.Globalization;
 
  [ExpressionConverterAttribute("MyMacro")]
  public class UsrMyMacro: IExpressionConverter 
  {
    public string Evaluate(object value, string arguments = "") 
    {
 
      // value passed in is an Id of some record
 
      var result = "";
 
      if (value != null) 
      {
        UserConnection userConnection = null;
        try
        {
          userConnection = (UserConnection) System.Web.HttpContext.Current.Session["UserConnection"];
        }
        catch {}
        if (userConnection == null) return result;
 
        var esq = new EntitySchemaQuery(userConnection.EntitySchemaManager, "UsrSomeEntity");
        esq.AddColumn("UsrSomeField1");
        esq.AddColumn("UsrSomeField2");
 
        var entity = esq.GetEntity(userConnection, Guid.Parse(value.ToString()));
        if (entity != null) 
        {
          var val1 = entity.GetTypedColumnValue<string>("UsrSomeField1");
          var val2 = entity.GetTypedColumnValue<string>("UsrSomeField2");
 
          result = val1 + " " + val2;
        }
      }
      return result;
    }
  }
}

One thing to note that is an issue if running the printable from a process with a timer, you'll be unable to get the UserConnection because in those cases the Session will be null.

Ryan

Show all comments