Post

1 follower Follow
0
Avatar

How to fetch the internal id from User Details screen

Hi,
By using Task Details screen's Resource--> How to fetch the internal id from User Details screen
my code is like that:
public string GetUserInternalID(string taskID)
{
Log4NetLib.FileLogService.logInfo(" Get resource for Task from Clarizen");
string resourceValue = "";
LoginDetails loggedIn = new LoginDetails();
loggedIn = Login();
try
{
BaseMessage[] msg = new BaseMessage[0];
EntityQuery eq = new EntityQuery
{
TypeName = "RegularResourceLink",
Where = new Compare
{
LeftExpression = new FieldExpression { FieldName = "Workitem" },
Operator = Operator.In,
RightExpression = new QueryExpression
{
Query = new EntityQuery
{
TypeName = "Task",
Where = new Compare
{
LeftExpression = new FieldExpression { FieldName = "SYSID" },
Operator = Operator.Equal,
RightExpression = new ConstantExpression { Value = taskID }
}
}
}
},
Fields = new string[] { "Resource.Name" }

};
msg = new BaseMessage[] { eq };
Result[] results = loggedIn.ClarizenClient.Execute(msg);

QueryResult qr = (QueryResult)results[0];
if (qr.Error == null)
{
Entity entity = qr.Entities[0];
FieldValue[] fieldValues = new FieldValue[] { entity.Values[0] };
Entity resource = (Entity)fieldValues[0].Value;
FieldValue[] resourceFieldValues = new FieldValue[] { resource.Values[0] };
resourceValue = resourceFieldValues[0].Value.ToString();
}
}
catch (Exception ex)
{
Log4NetLib.FileLogService.logError(" Error occured while fetching details of the Clarizen task from Clarizen : " + ex.StackTrace);
Log4NetLib.FileLogService.logError(Environment.NewLine + System.Reflection.MethodBase.GetCurrentMethod().Name + Environment.NewLine + "Error : " + DateTime.Now + Environment.NewLine + ex.Message);
Log4NetLib.FileLogService.logError(Environment.NewLine + Environment.NewLine + ex.StackTrace);
}

BaseMessage[] _messagesArray = new BaseMessage[0];
EntityQuery query = new EntityQuery();
query.TypeName = "User";
query.Fields = new string[] { "Name" };
Compare condition = new Compare();
condition.LeftExpression = new FieldExpression() { FieldName = "Name" };
condition.Operator = Operator.Equal;

condition.RightExpression = new ConstantExpression()
{
Value = new EntityId
{
TypeName = "User",
Value = resourceValue
}
};
query.Where = condition;

_messagesArray = new BaseMessage[] { query };
Result[] results1 = loggedIn.ClarizenClient.Execute(_messagesArray);

QueryResult qr1 = (QueryResult)results1[0];
if (qr1.Error == null)
{
Entity entity = qr1.Entities[0];
FieldValue[] fieldValues = new FieldValue[] { entity.Values[0] };

Entity user = (Entity)fieldValues[0].Value;
FieldValue[] userFieldValues = new FieldValue[] { user.Values[0] };

resourceValue = userFieldValues[0].Value.ToString();
}
return resourceValue;

}

Britto Antony Das

Please sign in to leave a comment.