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:
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:
We have read:
- https://cedocs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cl...
- https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
- https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
- https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...