Focal Point
[CLOSED] help on the Script object

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/1381057331/m/9977075276

September 08, 2014, 12:36 PM
cokeyng
[CLOSED] help on the Script object
Hi all,

I would need some help on how to access the XDDOC in javascript using the Script Object. In one of the documents that I found, it said that the XDDOC can only be available when executed as an iFL.

What does it mean?

Can anyone provide me some examples that I can follow?

Thanks

Cokey

This message has been edited. Last edited by: Tamra,


iWay 5.5, 6.01
Windows
all output (Excel, HTML, PDF)
September 08, 2014, 01:30 PM
cokeyng
never mind about the XDDOC. it is basically XDDocument. But is there a java documentation of the library?


iWay 5.5, 6.01
Windows
all output (Excel, HTML, PDF)
September 11, 2014, 03:52 PM
cokeyng
I got the script object working by following an example in iIT user guide. But the javascript example is very limited.


iWay 5.5, 6.01
Windows
all output (Excel, HTML, PDF)
September 15, 2014, 04:42 AM
Srii
What is your objective here? Which example have you been following?

XDDocument is iSM's internal document type.

-
Srii
October 14, 2014, 01:40 PM
cokeyng
For those who are interested, here is what I wanted to do. There is a column in the database containing dynamic JSON objects. The object will contains pairs of keys and values. like {"city":"Red Deer, Count of ", "dueDate":"2010-10-10"}.

As you can see, this json object will fail if I pass it to the json2xml services as it is missing the root tag. The following is the script that wrote to convert the tag in json to xml and append it to the end of the DocOut.

--------------------------------------------------------------------------------
importPackage(com.ibi.edaqm);
importPackage(com.iwaysoftware.iwscript);

function execute(){


var transformResult = new XDDocument();

var transform = tools.getTransform("QueryResult_TF");

var status = transform.execute(ctx.getDocIn(), ctx.getDocOut());

var root = ctx.getDocOut().getRoot();

var json_elements = new XDNode("JSON_Elements");

var json_to_xml = ctx.getDocOut().getRoot().findByName("JSON_XML");

var json_string = json_to_xml.getValue().replace('",', '";');

var json_string_new = json_string.replace('"', '').replace('{','').replace('}','');

var json_Array = json_string_new.split(";");

var newNode = null;

//tools.info("json_Arry = " + json_Array);
//tools.info("json_Array length = " + json_Array.length);

for (var i = 0; i < json_Array.length; i++){

if ((i == 0) && (json_Array[i].length() == 0)){
//do nothing

}else{
//tools.info("json_Array object " + i);
//tools.info("json_Array object = " + json_Array[i]);

var tag_name = json_Array[i].substring(0,json_Array[i].indexOf(":"));
var tag_value = json_Array[i].substring(json_Array[i].indexOf(":") + 1, json_Array[i].length());

newNode = new XDNode(tag_name.trim());
newNode.setValue(tag_value);

json_elements.setLastChild(newNode);
}
}

root.setLastChild(json_elements);

//tools.info("Testing of QueryResult_TF");


//ctx.setDocOut(transformResult);

//tools.debug(ctx.getDocOut());

return status;

}


iWay 5.5, 6.01
Windows
all output (Excel, HTML, PDF)