Dear All,
I have Sitecore JSON where topicbody is there and I want to get all values from topicbody
So I have written below groovy code
***************** MY GROOVY CODE *******************
def testMapList = [:]
testMapList[tabContent.itemId] = tabContent.title + "==" + tabContent.pocId + "=="+ tabContent
//testMapList[tabContent.itemId + "_metadata"] = tabContent
testMapList.each { key, value ->
def testTitle
def testPocId
def testMetadata
/* if( key.contains("_metadata")){
testMetadata = testMapList.get(key + "_metadata")
LOG.debug("testMetadata Value ==== ${testMetadata}")
} */
if (value.contains("==")){
testTitle = value.split("\\==")[0]
testPocId = value.split("\\==")[1]
testMetadata = value.split("\\==")[2]
LOG.debug("testMetadata Value ==== ${testMetadata}")
LOG.debug("testMetadata assignededitor Value ==== ${testMetadata.assignedEditor}") // here I am getting NULL
}
}
The issue is here that when I am trying to get the value of topicbody by using above command LOG.debug("testMetadata assignededitor Value ==== ${testMetadata.assignedEditor}") // here I am getting NULL , then I am getting NULL value.
Here topicbody values are coming fine like below
testMetadata Value ==== [__typename:KmAlgorithm, assignedEditor:mfad\M066721, assignedTo:mfad\MJS16, workflowItemManager:mfad\BRR04]
Thanks
Sonu
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @SUNITACH1
Just a reminder, this is an AEM community forum, and we advise on topics related to Adobe, specifically AEM. What you are asking seems to be a general topic that can be asked elsewhere for a more accurate answer. However, from what I can see, it appears that your testMetadata
is a string and not an object. That's why you cannot directly access the property using the 'dot' notation. You should first parse that string into JSON to access the information you need. Something like the following could work
import groovy.json.JsonSlurper
def testMapList = [:]
testMapList[tabContent.itemId] = tabContent.title + "==" + tabContent.pocId + "==" + tabContent
testMapList.each { key, value ->
def testTitle
def testPocId
def testMetadata
if (value.contains("==")) {
testTitle = value.split("\\==")[0]
testPocId = value.split("\\==")[1]
testMetadata = value.split("\\==")[2]
def metadataMap = new JsonSlurper().parseText(testMetadata)
LOG.debug("metadataMap Value ==== ${metadataMap}")
LOG.debug("assignedEditor Value ==== ${metadataMap.assignedEditor}")
}
}
Hope this helps.
My bad that I did not mention the below points. After getting above value I need to set those value in the metadata, like below
metadataNode.setProperty("mc:assignedEditor", metadataMap.assignedEditor)
But while doing the above I am getting below error
def jsonSlurper = new JsonSlurper()
def metadataMap = jsonSlurper.parseText(testMetadata)
LOG.debug("metadataMap Value ==== ${metadataMap}")
NOTE - I am getting like below value for testMetadata testMetadata= [__typename:KmAlgorithm, subjectMatterExpert:mfad\TMM03]
******************************** ERROR **************************
[ERROR]: Exception at method processPocList :: {} for this pocId
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
The current character read is '_' with an int value of 95
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 1
[__typename:KmAlgorithm
@SUNITACH1 Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies