Sunday, June 2, 2019

Web Services (SuiteTalk) : C# .Net Sample > Getting All Email/Messages within a Case

Below is a sample code demonstration how you can use C# and SuiteTalk Web Services to retrieve all email and message communication within the specified case.

Sample Code (C#)

public void retrieveAllCases()

        {

            NetSuiteService service = new NetSuiteService();

            LoginClass passport = new LoginClass();

            service.passport = passport.login();

 

            SupportCaseSearchBasic caseJoin = new SupportCaseSearchBasic();

           

           

            MessageSearch messageSearch = new MessageSearch();

 

            SearchMultiSelectField internalID = new SearchMultiSelectField();

            internalID.@operator = SearchMultiSelectFieldOperator.anyOf;

            internalID.operatorSpecified = true;

 

           

            RecordRef[] searchValue = new RecordRef[1];

 

           

            searchValue[0] = new RecordRef();

            searchValue[0].internalId = "7"; //Internal ID of the Desired case you want to retrieve the messages.

 

           

           

            internalID.searchValue = searchValue;

           

            caseJoin.internalId = internalID;

 

            messageSearch.caseJoin = caseJoin;

 

           

            SearchResult response = service.search(messageSearch);

 

            if (response.status.isSuccess)

            {

                Console.WriteLine("Total Record is:" + response.totalRecords);

                Record[] record = response.recordList;

                SearchRow []  searchRow = response.searchRowList;

                for (int i = 0; i < record.Length; i++)

                {

                    if(record[i] is Message)

                    {

                        Message message = (Message) record[i];

                        Console.WriteLine("Author: " + message.author.name + "\t" + message.message);

                    }

                }

            }

            else

            {

                StatusDetail[] statusDetail = response.status.statusDetail;

                for(var x = 0; x < response.status.statusDetail.Length; x++)

                {

                    Console.WriteLine("Error:" + statusDetail[x].type);

                    Console.WriteLine(statusDetail[x].message);

 

                }

            }

            Console.ReadLine();

        }

No comments:

Post a Comment