web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Adding items to array of type guid

(0) ShareShare
ReportReport
Posted on by 467

Hi all,

I am trying to add guids to an array of type guid in CRM 2016 On premise version

How can i do this any sample links/code please

Thanks in advance

Naren

I have the same question (0)
  • erhan.keskin Profile Picture
    2,253 on at

    Hi,

    Where do you do that? in jscript?

    Is that a field like regarding, to, cc?

    Regards,

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Hello,

    Refer to this sample C# code: 

    Guid id1 = new Guid("2d67aef2-3a29-4497-b4fc-b5d0c450ed48");
    Guid id2 = new Guid("d73368f1-6e6a-4c9e-933e-a658eb55b2c9");
    // Dynamic array of Guid type  
    Guid[] guidArray = new Guid[] {id1, id2};
    foreach(var id in guidArray)
        {
            Console.WriteLine("id : "   id);
        }
    
    Console.WriteLine("\n");
    // Dynamic array of a collection 
    List idsCollection = new List();
    idsCollection.Add(id1);
    idsCollection.Add(id2);
    foreach(var id in idsCollection){
        Console.WriteLine("id: "   id);
    }
    Console.ReadLine();
            

    Mehdi,

  • Narendra Sunkara Profile Picture
    467 on at

    Hi thanks for your reply

    I want in C# method

    I am passing array of string which will have guids with comma separated list.

    I need to validate each item whether it is a guid or not and return array of guids of type guid array.

    Public static guid[] isGuidArray(...)

  • meelamri Profile Picture
    13,216 User Group Leader on at

    Hello,

    Please check the code above. thank you.

  • erhan.keskin Profile Picture
    2,253 on at

    Hi,

    You can use Guid.Parse and Guid.TryParse for that.

    docs.microsoft.com/.../system.guid.parse

    docs.microsoft.com/.../system.guid.tryparse

    Regards,

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at

        static void Main(string[] args)
            {
                String[] guidsToValidate = new string[] { "2d67aef2-3a29-4497-b4fc-b5d0c450ed48", "falseId", "d73368f1-6e6a-4c9e-933e-a658eb55b2c9" };
                Guid guidToAdd;
                List  guidCollection = new List();
                foreach (var guidTovalidate in guidsToValidate)
                {
                    if(TryParseGuid(guidTovalidate, out guidToAdd))
                    {
                        guidCollection.Add(guidToAdd);
                    }
    
                }
                
                foreach(var id in guidCollection)
                {
                    Console.WriteLine("valid id: "   id);
                }
                Console.ReadLine();
            }
            //code found on stackoverflow
            public static bool TryParseGuid(string guidString, out Guid guid)
            {
                if (guidString == null) throw new ArgumentNullException("guidString");
                try
                {
                    guid = new Guid(guidString);
                    return true;
                }
                catch (FormatException)
                {
                    guid = default(Guid);
                    return false;
                }
            }

    Check this code. 

    Mehdi,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans