- Mark as New
- Follow
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Please check this article:
https://www.sitepoint.com/call-javascript-function-string-without-using-eval/
I am looking for a way to convert string to a function call without using eval. The reason for this is that I am using Json to store Appraisal Valuation Rules, and sometimes the rule is so complex that it has to be in a dedicated function. So, I decided to use standard function with two parameters only. The rule will look something like the following:
{
clients: ["Client 1", "Client 4", "Client 3"],
riskKey: "Risk_Key_XYZ",
riskCriteriaTempl: "('{0}' === 'Full' && '{1}' === 'No')",
riskRuleFields: ["FORM_TYPE", "other_land_conforms"],
highlightFields: [1],
riskProcessFunc: "xyz_function()",
riskFuncFields: {field1:"field1", field2:"field2"},
riskLevel: "High",
riskName_en: "Risk Name English",
riskName_fr: "Risk Name French",
}
So basically, the property "riskProcessFunc" will have the function name, and instead of using this format:
{...
riskProcessFunc: function (riskFields) {return xyz_function(this, riskFields)}
}
I will use this simplified format which can then be easily stored in Database or Excel Sheet:
{...
riskProcessFunc: "xyz_function()"
}
To make it clear, use the sample below:
function complexRule_xyz(a, b) {
console.println("It is working: " + a + ", " + b);
return "Yes!";
}
var funcName = "complexRule_xyz";
var myFn1 = new Function("p1", "p2", "return p1 + ', ' + p2");
var myFn2 = new Function("p1", "p2", "return " + funcName + "(p1, p2)");
var myFn3 = eval(funcName);
myFn1("po", "we");
myFn2("er", "rt")
myFn3("tr", "yu");
Try to execute the above using Console (ctrl-j) in Adobe Acrobat, and you will see that "myFn2()" won't work. Best is to use "eval()".
So ref. to the above article, the bottom line is how to use the "window" object from Adobe LiveCycle Designer Javascript?
Do you have other suggestions?
Tarek
Solved! Go to Solution.
Views
Replies
Total Likes