\$sp.getParameter("sys_id") returning "null" value in Service portal

DUGGI
Giga Guru

I am using $sp.getParameter("sys_id") in widget ,but it retun null,

anyone can help on this ?

15 REPLIES 15

Hi All,



Is there a way to get the sys_id of the widget in server script?



In Client script and html it is available as c.widget.sys_id



But when I tried it in server script, it is not working.



Any alternatives?



Thanks



Alli


A way I solved this was using sessions to store the URI values. So when the Model is run from the watcher it looks to a session variable for the page URI which was set on page load.   For example...



var session   = new GlideUtilSession();


var sys_id   = $sp.getParameter("sys_id");


     
if (sys_id != null ) {


      //   save value for record watcher as $sp not maintaining GET vars from initial page load. (due to request to model in the background).


      session.set("param_sys_id", sys_id);        


}else{


      //


      sys_id = session.get("param_sys_id");


}



Hope this helps.


Update: I've updated this code so that it is only utilised where the issue lies and that's within the post to the server (watchers etc...) because otherwise it will conflict with general page loading with certain scenarios and I've encountered.



var session   = new GlideUtilSession();


var sys_id   = $sp.getParameter("sys_id");


     
if (sys_id != null ) {


      //   save value for record watcher as $sp not maintaining GET vars from initial page load. (due to request to model in the background).


      session.set("param_sys_id", sys_id);        


}else{


      //


        if (input) {


                sys_id = session.get("param_sys_id");


        }


}


Admin Pro
Tera Contributor

Scott,


I am facing the exact same issue and came across your post after spending several hours figuring this out. I am trying to use the same code that you are using, but I get this error message "GlideUtilSession" is not defined. Did you have this issue? Im using this on a widget server script on Helsinki patch 4.


This is because that's a custom Script Include that I wrote which handles the GET and SET of session variables.   The core of this class is this method in-which both get() and set() call.



        ...


        _session : function(key, value)


        {


              if (typeof(value) != "undefined") {


                      //   set a session value


                      gs.getSession().putClientData(key, value);


              }      


              return gs.getSession().getClientData(key);      


        },


        ....


Hope this helps.