Question

Retrieve "Id" of record returned by Esq query?

		var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "F14Entities");
		esq.AddColumn("Id");
		esq.AddColumn("F14Name");
		esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "F14Name", oppositeReference.SchemaName));
		var entities = esq.GetEntityCollection(UserConnection);
		var oppositeReferenceId = Guid.Empty;
		if (entities.Count == 1) {
			oppositeReferenceId = entities.First().GetTypedColumnValue<Guid>("Id");
		}

The above code returns the following error:

Terrasoft.Common.ItemNotFoundException: Value "Id" was not found.
   at Terrasoft.Core.Entities.EntityColumnValueCollection.GetByName(String name)
   at Terrasoft.Core.Entities.Entity.InternalGetColumnValue(String valueName)
   at Terrasoft.Core.Entities.Entity.GetTypedColumnValue[TResult](String valueName)
   at Terrasoft.Core.Process.F14Process_cd99806MethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessScriptTask.InternalExecute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.ExecuteItem(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

How do I get the "Id" of the record returned by the ESQ query?

Thanks, 

Like 0

Like

3 comments

Please add a screenshot of the F14Entities entity in the object designer with all columns in it. The way you described in the code should work.

Try adding this to the ESQ: 

esq.PrimaryQueryColumn.IsAlwaysSelect = true;

Then you can access the Id using this: 

var id = entity.PrimaryColumnValue;

Ryan

Thank you Ryan, that worked.

Show all comments