u9.7 weboperation / webcall and params out
Author: yves.de.montmollin@aonhewitt.com (yves2m)
Hello, Question : I begin with Web and Uniface 9.7 and I don't understand well how things are working together I've this portion of code :
;--------------------------------------------------------------------------------------------------- ;Get params given with URL ( ...?k1=toto&k2=titi&k3=Something Else) ; getUrlParam ("k3", vVal ) --> vVal = "Something Else" ;--------------------------------------------------------------------------------------------------- weboperation getUrlParam params string pId : IN ; Param Name string pVal : OUT ; Value for this ParamName endparams javascript // Function found somewhere on the web that get the value for the param function getUrlPar (sVar) { return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\\\?]" + escape(sVar).replace(/[\\.\\+\\*]/g, "\\\\$&") + "(?:\\\\=([^&]*))?)?.*$", "i"), "$1")); } pVal = getUrlPar(pId); alert ("1: getUrlParam : " + pId + " = " + pVal); // Here the alert gives the right Id and Val return pVal; // Doesn't change anything endjavascript end ; getUrlParam ;--------------------------------------------------------------------------------------------------- ; Test for getUrlParam ;--------------------------------------------------------------------------------------------------- weboperation testGetUrlParam params endparams javascript // Get the infos like a $_Get in Php var vVal; uniface.getInstance("SFE100001BBIS").activate("getUrlParam", "k3", vVal); alert ("2: Value back from getUrlParam : " + vVal); // vVal is empty !!!!! endjavascript end ; testGetUrlParam
and when I try with this URL ".../SFE100001BBIS?k1=toto&k2=titi&k3=Something%20Else" I get a 1st alert with [1: getUrlParam : k3 = Somethnig Else] and a 2nd alert with [2: Value back from getUrlParam : undefined] I don't understand what I have to do to get the value for my param out Thanks for your help Yves
Hello Yves, the activate method works in asynchronous way. That's why you don't have return value. For doing this you have to use the Promise way:
weboperation getUrlParam
params
string pId : IN ; Param Name
endparams
javascript
// ...
return pVal;
endjavascript
end ; getUrlParam
weboperation testGetUrlParam
javascript
uniface.getInstance(“SFE100001BBIS”).activate(“getUrlParam”, “k3”).then(function(ret){
var val = ret.returnValue; // val returned by the promise
alert (“2: Value back from getUrlParam : ” + val);
}
endjavascript
end ; testGetUrlParam Author: Philippe (philippe.grangeray@agfa.com)
u9.7 weboperation / webcall and params out
Author: yves.de.montmollin@aonhewitt.com (yves2m)
Hello, Question : I begin with Web and Uniface 9.7 and I don't understand well how things are working together I've this portion of code :
;--------------------------------------------------------------------------------------------------- ;Get params given with URL ( ...?k1=toto&k2=titi&k3=Something Else) ; getUrlParam ("k3", vVal ) --> vVal = "Something Else" ;--------------------------------------------------------------------------------------------------- weboperation getUrlParam params string pId : IN ; Param Name string pVal : OUT ; Value for this ParamName endparams javascript // Function found somewhere on the web that get the value for the param function getUrlPar (sVar) { return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\\\?]" + escape(sVar).replace(/[\\.\\+\\*]/g, "\\\\$&") + "(?:\\\\=([^&]*))?)?.*$", "i"), "$1")); } pVal = getUrlPar(pId); alert ("1: getUrlParam : " + pId + " = " + pVal); // Here the alert gives the right Id and Val return pVal; // Doesn't change anything endjavascript end ; getUrlParam ;--------------------------------------------------------------------------------------------------- ; Test for getUrlParam ;--------------------------------------------------------------------------------------------------- weboperation testGetUrlParam params endparams javascript // Get the infos like a $_Get in Php var vVal; uniface.getInstance("SFE100001BBIS").activate("getUrlParam", "k3", vVal); alert ("2: Value back from getUrlParam : " + vVal); // vVal is empty !!!!! endjavascript end ; testGetUrlParam
and when I try with this URL ".../SFE100001BBIS?k1=toto&k2=titi&k3=Something%20Else" I get a 1st alert with [1: getUrlParam : k3 = Somethnig Else] and a 2nd alert with [2: Value back from getUrlParam : undefined] I don't understand what I have to do to get the value for my param out Thanks for your help Yves
Hello Philippe, Thanks for your answer. As I said, I'm new to web and I forogot the asynchrone working way.
It's clear to me now and I can continue Best regards Yves
Author: yves2m (yves.de.montmollin@aonhewitt.com)