locked
Read last 5 Characters from a field RRS feed

  • Question

  • I am creating a Workflow class in c#.

    I am looking to read in a field and pass its last 5 characters into a variable.

    I can read the field in and do a check condition against it like:

    querycontact.Criteria.AddCondition("phone", ConditionOperator.Equal, PhoneCheck);

    I just want to read in the last 5 characters of the field "phone" into a variable something like this:

    var number = ...("phone", 5) or something ... anyone know teh correct code I need to do this ?

    Thanks.

    Friday, February 28, 2014 10:42 AM

All replies

  • Hi,
    if you want to query only the last 5 digits you can use the EndsWith, for example:

    querycontact.Criteria.AddCondition("phone", ConditionOperator.EndsWith, "12345");

    if you want to extract the last 5 digits from a string you can use this code:

    string lastdigits = phone.Substring(Math.Max(0, phone.Length - 5));



    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, February 28, 2014 1:45 PM
  • Thanks for the reply:

    Could you do something like:

    var PhoneCheck = this.PhonetoQuery.Get(executionContext);

    string lastdigits = phone.Substring(Math.Max(0, phone.Length - 5));

    querycontact.Criteria.AddCondition("phone", ConditionOperator.Equal, PhoneCheck);


    What you think ?
    Friday, February 28, 2014 4:08 PM
  • You can't use a function to parse the last 5 characters within a QueryExpression.

    However , once you have the data, you can read the last 5 characters using SubString, e.g.

    string lastFive = phone.Substring(phone.Length-5)

    Where phone is a string variable read from the attribrute value.

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, February 28, 2014 4:09 PM
    Moderator