Hi,
I am trying to expand my CDT using expandcdt() function. It is given that the expand field parameter accepts input in "???function.expandcdt.param.expandField.description???" format. I am unable to figure out the input.
My CDT structure looks something like below,
empId: ""
empDepartment: Department(nested CDT)
dId:
dName: ""
empGender: Gender(nested CDT)
gId:
gName: ""
lastName: ""
firstName: ""
Could you please help me with an example.
Thanks in advance.
Discussion posts and replies are publicly visible
The expandcdt smart service function documentation is misleading. It is not documented well.
Here's an example of how you can use this function:
load(
local!topicCdt: {
{id: 1, topic: "SimpleTopic1", subTopicList: {"item1", "item2", "item3"}},
{id: 2, topic: "SimpleTopic2", subTopicList: {"item4", "item5", "item6"}}
},
expandcdt(
cdt: local!topicCdt,
expandField: "subTopicList"
)
And the output would be :
List of Dictionary: 6 items Dictionary
id: 1 topic: "SimpleTopic1" subTopicList: "item1"
Dictionary
id: 1 topic: "SimpleTopic1" subTopicList: "item2"
id: 1 topic: "SimpleTopic1" subTopicList: "item3"
id: 2 topic: "SimpleTopic2" subTopicList: "item4"
id: 2 topic: "SimpleTopic2" subTopicList: "item5"
id: 2 topic: "SimpleTopic2" subTopicList: "item6"
Hope this answers your question. Good luck!
Regards,
Sunil Zacharia
Hi Sunil, If given in your mentioned format it is working.If i tried taking my cdt as a rule input as below, expandcdt( cdt:ri!employee, expandField:"empGender" ) I am getting the error-"Expression evaluation error at function 'expandcdt'"
Here's another example with nested cdt's
load( local!subCdt: {it1: "item1", it2: "item2", it3: "item3"}, local!topicCdt: { {id: 1, topic: "SimpleTopic1", subTopicList: {a: local!subCdt, b: local!subCdt, c: local!subCdt}} }, expandcdt( cdt: local!topicCdt, expandField: "subTopicList" ))
local!subCdt: {it1: "item1", it2: "item2", it3: "item3"},
{id: 1, topic: "SimpleTopic1", subTopicList: {a: local!subCdt, b: local!subCdt, c: local!subCdt}}
Output:
List of Dictionary: 1 item Dictionary
id: 1 topic: "SimpleTopic1"
nest.a: Dictionary
it1: "item1"
it2: "item2"
it3: "item3"
nest.b: Dictionary
nest.c: Dictionary
Here's a cheeky solution for your problem. This code will give you list of column names in your cdt that have changed.
It does not work for nested cdt's but you can try to improve on this. Hope it helps.
load( local!disectCdt: rule!disectCDT( cdt1: 'type!<cdt>'(a: 1, b: "doc1", c: "desc1"), cdt2: 'type!<cdt>'(a: 1, b: "doc1", c: "") ), local!cdtColumns: index(index(local!disectCdt, "cdt1"), "columnArray"), local!cdt1Values: index(index(local!disectCdt, "cdt1"), "valueArray"), local!cdt2Values: index(index(local!disectCdt, "cdt2"), "valueArray"), local!changedColumnIndex: where( a!forEach( local!cdt1Values, fv!item <> local!cdt2Values[fv!index] ) ), index(local!cdtColumns, local!changedColumnIndex) )
And this is your supporting rule rule!disectCDT
if( runtimetypeof(ri!cdt1) <> runtimetypeof(ri!cdt2), null, load( local!cdt1ToColVal: split(stripwith(touniformstring(ri!cdt1),"[]"),","), local!cdt1Columns: a!forEach(local!cdt1ToColVal, split(fv!item, "=")[1]), local!cdt1Values: a!forEach(local!cdt1ToColVal, split(fv!item, "=")[2]), local!cdt2ToColVal: split(stripwith(touniformstring(ri!cdt2),"[]"),","), local!cdt2Columns: a!forEach(local!cdt2ToColVal, split(fv!item, "=")[1]), local!cdt2Values: a!forEach(local!cdt2ToColVal, split(fv!item, "=")[2]), { cdt1: { columnArray: local!cdt1Columns, valueArray: local!cdt1Values }, cdt2: { columnArray: local!cdt2Columns, valueArray: local!cdt2Values } } ) )