Skip to content

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

@aqeel-tassawar

Description

@aqeel-tassawar

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions