SysImage
photo
7.16

Hello Community,

 

We have a case where images that we inserted via the Database into SysImage went missing. The steps we followed was to insert records into SysImage directly and later map that image Id to the relevant section. 



Does Creatio automatically purge specific records in the SysImage table under ANY condition? If Yes, what are those conditions? Besides purging, does Creatio also go and update the reference Image Id column in the section?

 

I vaguely remember from a previous experience that Creatio did purge records based on some condition. Request your assistance.

Like 0

Like

3 comments

For those searching for an answer - 



Yes, Creatio does purge the record from SysImage if the referenced image column in the section is marked as NULL. 

M Shrikanth,

That is good to know. Thanks for posting this follow up!

Ryan

M Shrikanth,

Yes, that is correct. This is done by means of a stored procedure called tsp_CleanUpSysImageMSSql.

 

Best regards,

Bogdan S.

Show all comments
image
photo
7.16

Hello community



We have a use case where we need to migrate photos (Eg Contact display photo) into Creatio. We are aware that images are stored in the SysImage table, but going via the Database is not an option for us. 



I was looking into the 0/ImageAPIService/upload which is used by the platform internally when a Contact photo is uploaded. Can we use call API to upload an image into the SysImage table?? Subsequently we can map this Image the relevant record using the out of the box OData APIs. Few related questions below - 



1. Is the above API approach feasible?

2. I looked into what exact request was being sent and I notice a few query parameters - fileapi, totalFileLength, fileId and mimeType. If we were to replicate this request via code, Which of these are mandatory and which are optional? 

3. What does the query parameter "fileapi16123676529964" refer to? And what is that number??

4. Believe the unique Guid() for the SysImage record is generated on the client side, sent via the fileId query param and gets stored in the Id column in the SysImage table. Is this right?

5. Besides using the 0/ImageAPIService/upload API and the DB approach, is there any other way to import/migrate images into Creatio and map them to specific records?

Like 0

Like

6 comments
Best reply

M Shrikanth,

You can create a C# code schema with the following to add an image for an account or contact from a Url. This uses the ImageAPI found in the Terrasoft.Core.ImageAPI namespace.

var url = "https://somewebsite/someimage.png";
var entityType = "Account"; // or could be Contact
var entityId = someAccountId; // or contact Id
var imageField = "AccountLogoId"; // or if a contact, use "PhotoId"
 
using (var response = (WebRequest.Create(url) as HttpWebRequest).GetResponse())
{
	using (var responseStream = response.GetResponseStream())
	{
		using (var stream = new MemoryStream())
		{
			var fileId = Guid.NewGuid();
			responseStream.CopyTo(stream);
 
			var imageApi = new ImageAPI(UserConnection);
			imageApi.Save(stream, response.ContentType, url, fileId);
 
			using (var dbExecutor = UserConnection.EnsureDBConnection())
			{
				new Update(UserConnection, entityType)
					.Set(imageField, Column.Parameter(fileId))
					.Where("Id").IsEqual(Column.Parameter(entityId))
					.Execute(dbExecutor);
			}
		}
	}
}

This could be exposed as your own web service to simplify adding images to records. 

Hope this helps.

Ryan

Hello,

 

Please either use the database upload or use the standard approach of uploading files to the "Attachments and notes" detail. The ImageAPIService service is not supposed to be used for mass file upload and the database insert is the best approach in your case.

 

Best regards,

Oscar 

Oscar Dylan,



Hi Oscar. We do not want to migrate files into "Attachments & Notes" detail but rather migrate images so that they can be set as the profile picture (Ref screenshot https://prnt.sc/ylto0l). I don't think you can upload an image to the Attachments detail and then set it as the profile picture. Can you?



1. We have images stored in AWS S3 and not available in the file system to migrate. Hence, going via API is much more preferred than going via the DB.



2. Any specific reason why ImageAPIService should not or cannot be used? It is used by the platform when a user uploads a profile picture. Then why not use it from an external system??



3. Can you qualify what you mean by "mass file upload". Our use case is to migrate images before the system is used or goes live - We do not want to use this after the system has gone live or is being used by users. Given this context, Can you help with my questions above and also the original question of what the "fileapi" query parameter refers to?



4. Is the SysImage table exposed via OData? I verified that it is. But wasn't able to insert records into it via OData. I was able to do a GET request via OData and got the following results (https://prnt.sc/ylv178). When I tried to PATCH insert the image, I get a 405 Method not allowed (https://prnt.sc/ylvdor).



5. Is the SysImage table exposed via the Excel data import option? I could not find it being exposed. Am I missing something here?



Appreciate your help Oscar!

Oscar Dylan,

Hi Oscar, Can you help with the queries above? Thanks in advance.

M Shrikanth,

You can create a C# code schema with the following to add an image for an account or contact from a Url. This uses the ImageAPI found in the Terrasoft.Core.ImageAPI namespace.

var url = "https://somewebsite/someimage.png";
var entityType = "Account"; // or could be Contact
var entityId = someAccountId; // or contact Id
var imageField = "AccountLogoId"; // or if a contact, use "PhotoId"
 
using (var response = (WebRequest.Create(url) as HttpWebRequest).GetResponse())
{
	using (var responseStream = response.GetResponseStream())
	{
		using (var stream = new MemoryStream())
		{
			var fileId = Guid.NewGuid();
			responseStream.CopyTo(stream);
 
			var imageApi = new ImageAPI(UserConnection);
			imageApi.Save(stream, response.ContentType, url, fileId);
 
			using (var dbExecutor = UserConnection.EnsureDBConnection())
			{
				new Update(UserConnection, entityType)
					.Set(imageField, Column.Parameter(fileId))
					.Where("Id").IsEqual(Column.Parameter(entityId))
					.Execute(dbExecutor);
			}
		}
	}
}

This could be exposed as your own web service to simplify adding images to records. 

Hope this helps.

Ryan

Ryan Farley,

Hi Ryan. Thanks much for the alternate approach. 

Ryan Farley,

userconnection not working
Show all comments
report
printables
photo
7.11
studio

Hi!

How are you?

I hope you can help me!

How can I add the Employee image to my printable template? I add the "Photo" field of the Contact associated to Employee to template but it show an Guid instead of the Photo.

Thank you!

Regards,

Ezequiel

Like 0

Like

1 comments

Dear Ezequiel,

To get the picture of the contact, please check the screenshots below:

 Then within the contact object, please find photo and choose the image:

Within the printable template it Word it will look in such a way:

Best regards,

Lily

Show all comments
7.11
studio
photo
EmployeeImage

Hi everyone!

How are you?

I hope you can help me!

I need that in EmployeePage the Photo are not ReadOnly and it has funcionallity as in Contact. I saw that in attributes Section of EmployeePage(Base), there a attribute called ContactPhoto that refers to Contact.Photo and in the Init Method, this attribute is assigned to "primaryImageColumnName".I don't understand why "primaryImageColumnName" not is a attribute of Employee. What is its source?

To replicate this functionally, I did the following on EmployeePage (Custom):

  • I changed the attribute "ReadOnly" to False in array values of photoProperty in Diff section
  • I add "OnPhotoChange" attribute in array values of photoProperty in Diff section
  • I add OnPhotoChange and onPhotoUploaded to methods section 
//diff
{
	"operation": "merge",
	"parentName": "PhotoContainer",
	"propertyName": "items",
	"name": "Photo",
	"values": {
		"getSrcMethod": "getSchemaImageUrl",
		"readonly": false,
		"onPhotoChange": "onPhotoChange",
		"defaultImage": Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhoto),
		"generator": "ImageCustomGeneratorV2.generateCustomImageControl"
	}
},
 
...
//methods
onPhotoChange: function(photo) {
				if (!photo) {
 
					this.set(this.primaryImageColumnName, null);
					return;
				}
				this.Terrasoft.ImageApi.upload({
					file: photo,
					onComplete: this.onPhotoUploaded,
					onError: this.Terrasoft.emptyFn,
					scope: this
				});
			},
 
onPhotoUploaded: function(imageId) {
				debugger;
				var imageData = {
					value: imageId,
					displayValue: "Photo"
				};
				this.set(this.primaryImageColumnName, imageData);
			}

 

With this configuration, I can change the photo, but when I refresh or exit and return to the Page,the photo is reset with default image, I think it is not being recorded correctly in the contact photo column. What am I doing wrong? What is missing?

Thanks in advance.

King Regards,

 

Ezequiel

Like 0

Like

1 comments
Show all comments
image
photo
EmployeeImage
7.11
studio

Hi everyone!

How are you? I hope you can help me.

I need the default image of the employee to change dynamically depending if gender is Female O Male when the Photo not is set. I saw that the attribute Photo on Employee refers to Contact.Photo in attributes section of EmployeePage(Base)

How can I do this?

 

 

 

 

 

 

 

 

 

King Regards,

Ezequiel

 

Like 0

Like

2 comments

Dear Ezequiel,

 

You can achieve such task by applying some code modifications to the ContactPageV2. Please create or open ContactPageV2. Go to localizable strings (menu on the right) and add to Images your icon for female contacts.

Afterwards, please use this example to apply code modifications:

define("ContactPageV2", ["ContactPageV2Resources"],
	function(resources) {
		return {
			entitySchemaName: "Contact",
			attributes: {
				"DefaultImage": {
					dataValueType: Terrasoft.DataValueType.TEXT,
					type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
				}
			},
			methods: {
				onEntityInitialized: function() {
					this.callParent(arguments);
					this.setPhoto();
				},
				setPhoto: function() {
					var primaryImageColumnValue = this.get(this.primaryImageColumnName);
					if (!primaryImageColumnValue) {
						var gender = this.get("Gender").value;
						if (gender === "fc2483f8-65b6-df11-831a-001d60e938c6") {
							document.getElementsByClassName("ts-image-edit-full-size-element ts-image-style-rectangular")[0]
								.setAttribute("src",
									Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhotoFemale));
						} else {
							document.getElementsByClassName("ts-image-edit-full-size-element ts-image-style-rectangular")[0]
								.setAttribute("src",
									Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhoto));
						}
					}
				}
			},
			diff: /**SCHEMA_DIFF*/[
			]/**SCHEMA_DIFF*/
		};
	}
);

Here you can see, that based on the gender of the contact, the icon is set. Also, you can improve the code by adding onChange statement, which can change the icon if gender changes in runtime. 

Regards,

Anastasia

Anastasia Botezat,

one question

How can set image when onentityinitialized event is not triggered?

Show all comments