0
Answered

Create vendor by Macro

Dennis Rosenbaum 6 years ago updated 6 years ago 6

I am trying to create a new vendor by a Macro. But I can't get it to work. Anyone got a clue what is missing?



#set($providerService = $utils.getService('com.radzisz.xtrf.service.ProviderService'))

#set($branchService = $utils.getService('com.radzisz.xtrf.service.dictionary.BranchService'))

#set($countryService = $utils.getService('com.radzisz.xtrf.service.dictionary.CountryService'))

#set($defaultBranch = $$branchService.getHeadquarters())

#set($country = $countryService.getBySymbol("NL"))


#set($addressParameters = ["com.radzisz.xtrf.model.dictionary.Country","java.lang.String"])

#set($providerParameters = ["java.lang.String", "java.lang.String", "com.radzisz.xtrf.model.partner.Address"])

#set($address = $utils.createInstanceWithSpecificParamTypeNames('com.radzisz.xtrf.model.partner.Address', $addressParameters, $country, "email@gmail.com"))

#set($provider = $utils.createInstanceWithSpecificParamTypeNames('com.radzisz.xtrf.model.partner.provider.Provider', $providerParameters, "Dennis", "Dennis Rosenbaum", $address))

$provider.class


#set($newProvider = $provider.createReallyEmptyProvider())

$newProvider.setBranch($defaultBranch)<br>$newProvider.setName("Dennis Rosenbaum")

$newProvider.setCompanyName("Dennis Rosenbaum Company")

$newProvider.setAddress($address)


Creating...

$providerService.create($newProvider)

Created...

GOOD, I'M SATISFIED
Satisfaction mark by Dennis Rosenbaum 6 years ago
Answered

Hi Dennis, please request a development of our API in this respect explaining the need behind it.

Dear Lukasz, I do understand that I could request API development (I will also do that). But in my previous experiences I noticed how slow such development goes. And as our business stays behind every day we do nothing I prefer to have this functionality completed as soon as possible.

According to your documentation there should be a 'create' function for entities within , but there is no explanation or error that I receive when executing this line: $providerService.create($newProvider). So I expect I have missed a simple and small but important step.

Wouldn't it be easier for you, and for me, if we don't go through the hassle of creating new API calls?

Dear Dennis, 

Services in most cases are not included in the docs we provide to our Customers because of possible severe damage that may occur by using those without enough caution. The second reason is that these require some knowledge about constraints in the model we're using so it's not the most user-friendly and safe way to do things. These are meant for our developers and customization team mostly. 


That being said, we recommend to dig into the system logs (server.log is the one you should take a look at) and find the exception you get. Please share it with our Service Desk via Jira so we can assist you further.


Kind regards,

Bartosz

Dear Bartosz,

Thank you for this explanation. The server.log will help me for future reference.


Kind regards,
Dennis Rosenbaum

+1

Hi Dennis,


Try this:


#set($providerService = $utils.getService('com.radzisz.xtrf.service.ProviderService'))
#set($branchService = $utils.getService('com.radzisz.xtrf.service.dictionary.BranchService'))
#set($countryService = $utils.getService('com.radzisz.xtrf.service.dictionary.CountryService'))
#set($defaultBranch = $$branchService.getHeadquarters())
#set($country = $countryService.getBySymbol("NL"))

#set($addressParameters = ["com.radzisz.xtrf.model.dictionary.Country","java.lang.String"])
#set($providerParameters = ["java.lang.String", "java.lang.String", "com.radzisz.xtrf.model.partner.Address"])
#set($address = $utils.createInstanceWithSpecificParamTypeNames('com.radzisz.xtrf.model.partner.Address', $addressParameters, $country, "email@gmail.com"))
#set($provider = $utils.createInstanceWithSpecificParamTypeNames('com.radzisz.xtrf.model.partner.provider.Provider', $providerParameters, "Dennis", "Dennis Rosenbaum", $address))
$provider.class

#set($newProvider = $provider.createEmpty())
$newProvider.setBranch($defaultBranch)
$newProvider.setName("Dennis Rosenbaum")
$newProvider.setFullname("Dennis Rosenbaum Company")
$newProvider.setAddress($address)

Creating...

$providerService.create($newProvider)

Created...

I only made two minor changes to your code and it seems to work now: I used createEmpty() instead of createReallyEmptyProvider() and changed setCompanyName() to setFullname().



Great! Thank you for helping Angela. It indeed works now.