10 Replies Latest reply: Apr 21, 2014 4:31 PM by Jim.Marion-Oracle RSS

    Component Variables access in Iscript

    PStechi

      Hi guys, I hope you all doing well. I have a question regarding Component Variables,any help will really appreciated

       

      Is it possible to pass Component Variables to Iscript? If yes please tell me how can i do that.

       

      Best Regards,

        • 1. Re: Component Variables access in Iscript
          user1125113

          I used component level variables in PS pages and they are accessible. Means I set the component level variable in one page and able to access that value from another PS page. But i never try it for IScript, may its also workable for Iscript too.

          • 2. Re: Component Variables access in Iscript
            Jim.Marion-Oracle

            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.

            • 3. Re: Component Variables access in Iscript
              PStechi

              Thanks for reply . Jim can you please share any example or refer any document which help me to pass values to an iScript through URL or posting them to the iScript.

              • 4. Re: Component Variables access in Iscript
                Jim.Marion-Oracle

                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

                • 5. Re: Component Variables access in Iscript
                  PStechi

                  Can you please again share the Link. I think in above post you give the link of this Discussion.

                  • 6. Re: Component Variables access in Iscript
                    Jim.Marion-Oracle

                    Interesting. I updated the link.

                    • 7. Re: Component Variables access in Iscript
                      PStechi

                      Hi Jim, I am appending parameters in my URL using this syntax

                       

                      Local string &param1=Record.Field.Value;

                      Local string &param2=Record.Field.Value;

                      Local string &parameter = &parameters | "parm1=" | &param1;

                      &parameters = &parameters | "parm2=" | &param2;

                      Local string &url = GenerateScriptContentURL(%Portal, %Node, Record.WEBLIB_REC, Field.ISCRIPT1, "FieldFormula", "IScript_HelloWorld?" | &parameters);

                      %Response.RedirectURL(EncodeURL(&url));

                       

                      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.

                      • 8. Re: Component Variables access in Iscript
                        Jim.Marion-Oracle

                        Here are a couple of recommendations:

                         

                        1. 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.
                        2. 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:

                         

                        1. 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.
                        2. 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!

                        • 9. Re: Component Variables access in Iscript
                          PStechi

                          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   

                          • 10. Re: Component Variables access in Iscript
                            Jim.Marion-Oracle

                            It really depends on the content and use case.