Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Adding items to array of type guid

Posted on by 465

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

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Adding items to array of type guid

        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,

  • erhan.keskin Profile Picture
    erhan.keskin 2,247 on at
    RE: Adding items to array of type guid

    Hi,

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

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

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

    Regards,

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Adding items to array of type guid

    Hello,

    Please check the code above. thank you.

  • Narendra Sunkara Profile Picture
    Narendra Sunkara 465 on at
    RE: Adding items to array of type guid

    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(...)

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Adding items to array of type guid

    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,

  • erhan.keskin Profile Picture
    erhan.keskin 2,247 on at
    RE: Adding items to array of type guid

    Hi,

    Where do you do that? in jscript?

    Is that a field like regarding, to, cc?

    Regards,

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans