By component variables, I assume you mean component scoped variables? No, an iScript is outside the component and cannot access component scoped variables. It cannot access the component buffer either. You can pass values to an iScript through the URL or post them to the iScript, but you cannot access them as if they already exist. You can access global variables, but I discourage the use of global variables. They are too hard to track and are easy to introduce side effects.
You pass them as standard query string value pairs. For example, if your iScript was named IScript_PromoteEmployee, then you would have a URL that ended in something like this..../IScript_PromoteEmployee?EMPLID=KU0010. The iScript PeopleCode accesses parameters through the %Request object as in %Request.GetParameter("EMPLID"). There is a great write up about iScripts at What is an IScript?
Message was edited by: jim.marion -- updated link
Hi Jim, I am appending parameters in my URL using this syntax
Local string ¶m1=Record.Field.Value;
Local string ¶m2=Record.Field.Value;
Local string ¶meter = ¶meters | "parm1=" | ¶m1;
¶meters = ¶meters | "parm2=" | ¶m2;
Local string &url = GenerateScriptContentURL(%Portal, %Node, Record.WEBLIB_REC, Field.ISCRIPT1, "FieldFormula", "IScript_HelloWorld?" | ¶meters);
But when it redirect to my Iscript it give this error
Decimal division by zero occurred. (180,109) WEBLIB_REC.ISCRIPT1.FieldFormula Name:IScript_HelloWorld PCPC:4889 Statement:101
Can you please tell me what's going wrong.
Here are a couple of recommendations:
- Move the ? outside the function name in the GenerateScriptContentURL function. The function name is IScript_HelloWorld. You should append the question mark AFTER the function name, but before the parameters section.
- Encode each parameter using EncodeURLForQueryString. Don't encode the entire URL.
The PeopleCode generates a URL, it does not return a response. You are using a redirect. If you are seeing a "Decimal Division by Zero" error and it is telling you that the error is in IScript_HelloWorld, then look at two things:
- The URL in your iframe or window. Is it the iScript URL? If so, then your redirect was successful. Since the PeopleCode error tells you it happened in the iScript, then I already know the redirect was successful, but the URL test is a great way to confirm.
- Look at your iScript PeopleCode and find the division by zero error. The response says that it is in the iScript, not in the code that performs the redirect.
I hope this helps!
Thank you so much @jim.marion your first suggestion is working for me When I move ? outside of the function name in GenerateScriptContentURL function it append my parameters in URL. Here I want to share if Encode each parameter using EncodeURLForQueryString or even not encode with any function it still append parameters in URL and from this URL i can access my parameters using Request.GetParameter function.
@jim.marion here i want another suggestion from you, should i have to encode complete URL or only encode parameters.because when i encode complete URL then i am not able to access my parameters in Iscript.
Thanks once again