Thus I started working towards removing dependency on JAVA business service and created complete eScript based solution as ver2 of EAI JSON Converter business service.
Generate JSON in Siebel without Java |
This service will have the same methods and arguments, and will outputs similar JSON string and property set as previous version did but without the need of JDK. It is complete plug and play service, just copy paste the code and start using the service.
function CreateJSON(Inputs){Hope the code is self explanatory. Feel free to edit it for your implementation. I have tested the output and validated for RFC4627.
/*********
Created By: Jim
Support: http://howtosiebel.blogspot.com
*********/
var str,j;
var propName = "";
var propVal = "";
str = "{";
propName = Inputs.GetFirstProperty();
//Type and value
if(Inputs.GetValue() != null && Inputs.GetValue() != ""){
str = str + '"' + Inputs.GetType() + '"' + ":" + '"' + Inputs.GetValue() + '"';
if(propName != "") str= str + ",";
}
//Properties
while (propName != "") {
propVal = Inputs.GetProperty(propName);
str = str + '"' + propName + '"' + ":" + '"' +propVal + '"';
propName = Inputs.GetNextProperty();
if(propName != "") str = str + ",";
}
propName = Inputs.GetFirstProperty();
if(propName != "" && Inputs.GetChildCount()> 0)str = str + ",";
//Loop for child
if(Inputs.GetChildCount()> 0){
if(Inputs.GetChildCount()> 1)str = str + '"Object"' + ":" + "{";
for (var i = 0; i < Inputs.GetChildCount(); i++){
j = Inputs.GetChild(i);
str = str + '"' + j.GetType() + i + '"' + ":" + CreateJSON(j);// + ",";
if(i+1<Inputs.GetChildCount()) str =str + ",";
}
if(Inputs.GetChildCount()> 1)str = str + "}";
}
str = str + "}";
return str;
}
Creating JSON string from property set was easy I traversed through the property set using out of the box Siebel methods and created the string. Creating propset from JSON proved difficult, I am still working on solution for interpreting JSON and converting it into property set, I have made some progress will post it as soon as it is working satisfactorily.
If you want to contribute in nobel cause then contact me via comments below and don't forget to plus one this post on Google. All comments are welcome.