Question
· Mar 26, 2020

Correct way to set a value into a list?

Hello,

 

We have a tranformation where we would like to convert a date from the following format:

"'dd/mm/yyyy' 'hh:mm'" (double quotes are just visual to indicate this is a string)

to date and time separated:

date: dd/mm/yyyy

time: hh:mm

 

We have already splitted the datetime into date and hour as follows:

 

  set fechaHora = source.result.GetAt(indice).fechaHora
 
  $$$LOGINFO("fechaHora: "_fechaHora)
 
  set fechaHoraSinComillas = $replace(fechaHora,"'","")
 
  $$$LOGINFO("fechaHoraSinComillas: "_fechaHoraSinComillas)  
 
  set fecha = $piece(fechaHoraSinComillas," ")
 
  $$$LOGINFO("fecha: "_fecha)
 
  set hora = $piece(fechaHoraSinComillas," ",2)
 
  $$$LOGINFO("hora: "_hora)

 

We would like to assign fecha (date) and hora (hour), each one, to a variable inside a list, called datos (data)

 

 

We have done it using two assigns as follows:

<transform sourceClass='Mensajes.Response.HistoriaClinica.ConsultaCitaEspecializadaResponse' targetClass='Mensajes.Response.HistoriaClinica.ConsultaCitasResponse' create='new' language='objectscript' >
<foreach property='source.result()' key='indice' >
<code>
<![CDATA[
  set fechaHora = source.result.GetAt(indice).fechaHora
  
  $$$LOGINFO("fechaHora: "_fechaHora)
  
  set fechaHoraSinComillas = $replace(fechaHora,"'","")
  
  $$$LOGINFO("fechaHoraSinComillas: "_fechaHoraSinComillas)
  
  set fecha = $piece(fechaHoraSinComillas," ")
  
  $$$LOGINFO("fecha: "_fecha)
  
  set hora = $piece(fechaHoraSinComillas," ",2)
  
  $$$LOGINFO("hora: "_hora)
 
  
]]></code>
<assign value='fecha' property='target.datos.(indice).fecha' action='set' />
<assign value='hora' property='target.datos.(indice).hora' action='set' />
<code>
<![CDATA[
  $$$LOGINFO("Nueva fecha: "_target.datos.GetAt(indice).fecha)
  
  $$$LOGINFO("Nueva hora: "_target.datos.GetAt(indice).hora)]]></code>

 

And we check in the Production that the logs output what is expected:


Nueva fecha: 31/03/2020  

Nueva hora: 08:26  

 

 

However, how could we replace those two assigns which put fecha and hora into the variables inside the datos list; to use custom code?

 

We have already tried:

 

  set fechaHora = source.result.GetAt(indice).fechaHora
 
  $$$LOGINFO("fechaHora: "_fechaHora)
 
  set fechaHoraSinComillas = $replace(fechaHora,"'","")
 
  $$$LOGINFO("fechaHoraSinComillas: "_fechaHoraSinComillas)  
 
  set fecha = $piece(fechaHoraSinComillas," ")
 
  $$$LOGINFO("fecha: "_fecha)
 
  set hora = $piece(fechaHoraSinComillas," ",2)
 
  $$$LOGINFO("hora: "_hora)
 
 
  do target.datos.InsertAt(fecha,indice).fecha
  do target.datos.InsertAt(hora,indice).hora

 

Being the output:

 

ERROR <Ens>ErrException: <SYNTAX>zTransform+19^Transformaciones.HistoriaClinica.ConsultaCitasEspecializadaToConsultaCitas.1 -- logged as '-' number - @' do target.datos.InsertAt(fecha,indice).fecha'

 

In addition we have also tried:

  set fechaHora = source.result.GetAt(indice).fechaHora
 
  $$$LOGINFO("fechaHora: "_fechaHora)
 
  set fechaHoraSinComillas = $replace(fechaHora,"'","")
 
  $$$LOGINFO("fechaHoraSinComillas: "_fechaHoraSinComillas)  
 
  set fecha = $piece(fechaHoraSinComillas," ")
 
  $$$LOGINFO("fecha: "_fecha)
 
  set hora = $piece(fechaHoraSinComillas," ",2)
 
  $$$LOGINFO("hora: "_hora)
 

 
 
  set target.datos.GetAt(indice).fecha = fecha
  set target.datos.GetAt(indice).hora = hora


 
   

 

Being the output:

 

ERROR <Ens>ErrException: <INVALID OREF>zTransform+23^Transformaciones.HistoriaClinica.ConsultaCitasEspecializadaToConsultaCitas.1 -- logged as '-' number - @' set target.datos.GetAt(indice).fecha = fecha'
 
 
Could you help us?

 

 

We have read:

  1. https://cedocs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cl...
  2. https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
  3. https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
  4. https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
Discussion (1)2
Log in or sign up to continue

Yone, what is the data type of the property "datos" in Mensajes.Response.HistoriaClinica.ConsultaCitasResponse. I assume it's a list of a custom class that has two properties named fecha and hora?

Property datos as List of my.class.dato;

If so, you would do something like this:

set dato=##class(my.class.dato).%New()
set dato.fecha=fecha
set dato.hora=hora
do target.datos.InsertAt(dato,indice)