Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the Status of APPYMT from 'A' to 'C' #238

Open
aqeel-tassawar opened this issue Jun 27, 2023 · 0 comments
Open

update the Status of APPYMT from 'A' to 'C' #238

aqeel-tassawar opened this issue Jun 27, 2023 · 0 comments

Comments

@aqeel-tassawar
Copy link

I have a requirement to update the Status of APPYMT from 'A' to 'C' using the sdk. Its not throwing any errors or exception but doesn't update the status to 'C' and it updates any other fields.
Do you an example of updating the status to from 'A' to 'C'

public async Task<IDataResponse> Update(List apPymts)
{
return await _intacctDataService.InsertUpdateBatch(apPymts, "update");
}

  public async Task<IDataResponse<T>> InsertUpdateBatch(List<T> document, string action)
    {
        object documentToProcess = null;

        Type documentType = document[0].GetType();

        //is this a base Intacct object
        if (documentType.GetCustomAttribute<IntacctObjectAttribute>() == null)
        {
            //if not, let's find the object
            foreach (PropertyInfo propertyInfo in documentType.GetProperties())
            {
                if (propertyInfo.PropertyType.GetCustomAttribute<IntacctObjectAttribute>() != null)
                {
                    documentToProcess = documentType.GetProperty(propertyInfo.Name).GetValue(document, null);
                    break;
                }
            }

            if (documentToProcess == null)
                documentToProcess = document;
        }
        else
            documentToProcess = document;



        //add to the list to process
        List<IFunction> functions = new List<IFunction>();

        foreach (var doc in (List<T>)documentToProcess)
        {
            if (action != string.Empty)
                ((IIntacctObject)doc).Operation = action;
            ((IIntacctObject)doc).ClientVersion = _integrationRegistration.clientApplicationVersion;
            functions.Add((IFunction)doc);
        }

        Task<OnlineResponse> createTask = _onlineClient.ExecuteBatch(functions);
        DataResponse<T> dataResponse = new DataResponse<T>(document[0]);

        try
        {
            createTask.Wait();
            OnlineResponse createResponse = createTask.Result;
            dataResponse.Status = System.Net.HttpStatusCode.Created;

            foreach (var result in createResponse.Results)
            {
                Message message = new Message();

                message.MessageCode = result.Status;

                if (result.Status.ToUpper() == "SUCCESS")
                {
                    if (result.Data != null)
                        message.MessageText = result.Data[0].Value;
                    else
                        if (result.Key != null)
                        message.MessageText = result.Key;
                }
                else
                {
                    StringBuilder errorText = new StringBuilder();

                    foreach (var error in result.Errors)
                    {
                        errorText.Append(error);
                        errorText.AppendLine();
                    }

                    message.MessageText = errorText.ToString();
                }

                dataResponse.Messages.Add(message);
            }
        }
        catch (Exception ex)
        {
            dataResponse.Status = System.Net.HttpStatusCode.InternalServerError;
            dataResponse.Messages.Add(new Message() { MessageText = ex.Message });

            using (_logger.BeginScope(_integrationRegistration.id))
            {
                _logger.LogError(ex, $"Error when inserting batch {documentToProcess.GetType().ToString()}");
            }
        }

        return dataResponse;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant