Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Storing and retrieving an xml variable in DB

Avatar

Level 8
Level 8
Hi all,



I am having some trouble storing and retrieving an xml variable in a custom DB. Can it be done via the jdbc-services or do I need to create some custom code which I call in an execute script?



In either case, how?



Thanks in advance



Sincerely

Kim Christensen
7 Replies

Avatar

Level 10
"Can it be done via the jdbc-services?"

Yes



You might want to store it in a String variable if you run into problem with the XML.



Jasmin

Avatar

Level 8
Level 8
Ok, thanks alot...



I just had the problem that I didn't get any data inserted in the database.



I have set up the execute sql service to the following:



SQL Statement:



insert into table1 values({$ /process_data/@id $}, '{$ /process_data/formdata $}')



This inserts the processInstanceID in the DB but no data is inserted. I have also tried:



insert into table1 values({$ /process_data/@id $}, {$ /process_data/formdata $}) (without the quotes (' and '))



But this time the server gets an exception parsing the xml.



How should I set up the SQL statement to insert my xml-variable "formdata" into the DB?



Thank you in advance



Sincerely

Kim Christensen

Avatar

Former Community Member
That is because you are not referencing your form data correctly. How is formdata defined? Are you doing this from a submitted form (through workspace)?

Avatar

Level 10
You might have to convert it into a string.



Use the function serialize(/process_data/formdata) to have a string representation of you XML.



Jasmin

Avatar

Level 8
Level 8
The form is submitted by email and the process is kicked of by an email endpoint. How should I reference my formdata variable?



\Kim

Avatar

Former Community Member
What is the variable type tha is recieving the submitted data? XML?

Avatar

Level 8
Level 8
Sorry for the late post - I got it working at last but just inserting the xml as a string into the db



Kim