Question

How to get attachments and Some Header Feilds from Custom Object.

Hello Everyone,

I have a Requirement to upload Attachment and Some header fields of Custom Object to another Application Through API. I m able to get header data from a Custom Webservice but not sure how to get attachment that can be uploaded to another Application. 

Like 0

Like

4 comments

Hi!

 

You can write a custom web service in Creatio that retrieves the required attachment(s) from the custom object, formats the data appropriately, and sends it to the other application's API using HTTP requests. Alternatively, you could look into using a pre-built integration tool or middleware solution that can facilitate the transfer of data between applications in the marketplace. As an example, if you would intend to use DocuWare for your uploaded attachments -https://marketplace.creatio.com/app/docuware-connector-creatio.

 

Hope this info was helpful.

Hi! 

 

I would like to add that you might find the relevant information about the API file attachments on this page of the Academy - https://academy.creatio.com/docs/user/setup_and_administration/base_int…

 

We will be glad to help with any other questions.

Hello Everyone ,

Well I tried Creating WebService that can get and post the Data in Attachment Section but When i Try to Get the Data Using Record id its not getting it. Can you please Advise .

Screenshot of Postman is Attached and the Code of WebService

Code : 





 

namespace Terrasoft.Configuration.UsrCustomConfigurationServiceNamespace

{

using System;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.ServiceModel.Activation;

using Terrasoft.Core;

using Terrasoft.Web.Common;

using Terrasoft.Core.Entities;

using System.Collections.Generic;



[ServiceContract]

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

public class UsrCustomConfigurationService : BaseService

{

    /* The method that creates a new record in the SysFile entity. */

    [OperationContract]

[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,

    ResponseFormat = WebMessageFormat.Json)]

public string CreateSysFileRecord(string data, string fileGroup, string id, string name, int size,

    string sysFileStorage, string type, string recordId, string recordSchemaName)

{

    UserConnection userConnection = GetUserConnection();

    EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;

    EntitySchema entitySchema = entitySchemaManager.GetInstanceByName("SysFile");

    Entity entity = entitySchema.CreateEntity(userConnection);

    entity.SetDefColumnValues();

    entity.SetColumnValue("Data", Convert.FromBase64String(data));

    entity.SetColumnValue("FileGroup", new Guid(fileGroup));

    entity.SetColumnValue("Id", new Guid(id));

    entity.SetColumnValue("Name", name);

    entity.SetColumnValue("Size", size);

    entity.SetColumnValue("SysFileStorage", new Guid(sysFileStorage));

    entity.SetColumnValue("Type", new Guid(type));

    entity.SetColumnValue("RecordId", new Guid(recordId));

    entity.SetColumnValue("RecordSchemaName", recordSchemaName);

    if (!entity.Save())

    {

        throw new Exception("Failed to create SysFile record");

    }

    return entity.PrimaryColumnValue.ToString();

}

/* The method that retrieves a SysFile record by ID. */

[OperationContract]

[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,

ResponseFormat = WebMessageFormat.Json)]

public Dictionary<string, object> GetSysFileById(string id) {

    /* The default result. */

    var result = new Dictionary<string, object>();

    /* The EntitySchemaQuery instance that accesses the SysFile database table. */

    var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "SysFile");

    /* Add columns to the query. */

    var colId = esq.AddColumn("Id");

    var colName = esq.AddColumn("Name");

    var colData = esq.AddColumn("Data");

    var colSize = esq.AddColumn("Size");

    var colFileGroup = esq.AddColumn("FileGroup");

    var colSysFileStorage = esq.AddColumn("SysFileStorage");

    var colType = esq.AddColumn("Type");

    var colRecordId = esq.AddColumn("RecordId");

    var colRecordSchemaName = esq.AddColumn("RecordSchemaName");

    /* Filter the query data. */

    var esqFilter = esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", id);

    esq.Filters.Add(esqFilter);

    /* Retrieve the query results. */

    var entities = esq.GetEntityCollection(UserConnection);

    /* If the service receives data. */

    if (entities.Count > 0)

    {

        var entity = entities[0];

        /* Add the values of the record fields to the result dictionary. */

        result.Add("Id", entity.GetTypedColumnValue<Guid>(colId.Name));

        result.Add("Name", entity.GetTypedColumnValue<string>(colName.Name));

        result.Add("Data", entity.GetTypedColumnValue<byte[]>(colData.Name));

        result.Add("Size", entity.GetTypedColumnValue<int>(colSize.Name));

        result.Add("FileGroup", entity.GetTypedColumnValue<Guid>(colFileGroup.Name));

        result.Add("SysFileStorage", entity.GetTypedColumnValue<Guid>(colSysFileStorage.Name));

        result.Add("Type", entity.GetTypedColumnValue<Guid>(colType.Name));

        result.Add("RecordId", entity.GetTypedColumnValue<Guid>(colRecordId.Name));

        result.Add("RecordSchemaName", entity.GetTypedColumnValue<string>(colRecordSchemaName.Name));

    }

    // Return the results.

    return result;

}

}

}

Show all comments