Codeless: Adding property to request item in Codeless

Hi,

I am trying to save a file on the Before Create trigger on data table I have.

the request item has a property “logo” which will get saved as a file and I want to attach the returned URL to a property “companyLogo” of the RequestItem before its saved.

The saving part is working great, however I am unable to attach the URL to the request item before its being saved.

attached below is my cordless block.

Any help or guidance will be appreciated as I am pretty sure something is wrong with my logic.

Thank you

Try returning the “Request item” object

hey Mark,

Thanks for the reply.

First of all Big Fan of your work, and thank you for this amazing product.

I have tried the following with no change


I believe the object is being created before the URL returns

Hi Omar,

Are you sure the “if” check to see of logo is a type of object passes? Have you validated it? Perhaps with the print block and then checking in the logs?

Regards,
Mark

Hey Mark,

I believe the if block passes because the file gets saved properly in the provided folder and overwrites as expected.

but I will check your method as well and report back

I just double checked the logs and the if block works as expected and I even printed the url to the log.

I even printed the property companyLogo from the request item after I have set it to the URL it prints the correct URL address.

I don’t know if I mentioned earlier, companyLogo on my table schema is of type File Reference

Yes, the fact that the event handler is marked as non-blocking definitely explains why the property is not set. Backendless will not wait for the result of a non blocking event handler and will proceed with saving the object immediately after it fires off the event handler (ignoring what the handler returns).

Additionally, I looked at the logic in the afterCreate event handler and it could benefit from some optimizations. The logic makes 5 API calls, however, you could simplify it by using the DeepSave block and reduce the API calls to one.

Regards,
Mark

Hey Mark,

Thanks once again for the guidance I ended up refactoring all the cloud code with a custom service. Everything is working as expected now and this is how I managed to accomplish it.

I Don’t know if this code or (codeless block) can be made more efficient but is working as expected.

Regards,
Omar

Hi Omar,

Good progress! You could optimize it even more by getting rid of the Add Object Relations and using the Depp Save block to save the root object in the Client table.

Regards,
Mark

Hey mark,

I was thinking of that but the “Client” which is the parent object in this case gets Saved at an earlier process from within the APP I didn’t know if deep save will work similarly tom a similar fashion as Upsert.

Would love your two cents on the topic.

Hi Omar,

DeepSave can handle both object creation as well as object update. The root object can already be in the system by the time when you call DeepSave.

Regards,
Mark

Hey Mark,

I have been trying to implement you suggestion with deep save on the parent object.
when I do that I can’t seem to be able to access the object properties of the children. I printed to log and this is my request object

{
client: {
venues: [ [Object], [Object], [Object] ],
location: { coordinates: [Array], type: ‘Point’ },
companyName: ‘Abu Talals’,
contacts:
}
}

when I am attempting to get any properties from the venues array I get error 'cannot read property ‘name’ of undefined.

attached below is my codeless block

image

I think there is a mistake. Your object hasn’t logo property, but it’s not a null it’s an undefined