Variable sys_id in widget server side script

ohhgr
Kilo Sage
Kilo Sage

Hello All,

I was stuck on this particular point and hope someone can point me in right direction.

I want to create a reusable widget (say a modified date picker), I would use it as a variable in multiple catalog items. Now, I'd like some options to dynamically change based on some options specified at the variable definition. (I could store them in a different table in future, but for simplicity assume that one additional field stores this information on 'item_option_new' table. My question is how can I identify which variable is being called in widget's server script?

In client controller I can get this information by using $scope.page.field.sys_id. But, I'd like to have this information at the server side so that I could provide the options from server side.

-Mandar

1 ACCEPTED SOLUTION

xiaix
Tera Guru

I completely understand what you're trying to do... or so I think.  I'm in the same boat.

 

I have a catalog item on the Service Portal to where I added a macro variable that loads a widget:

find_real_file.png

 

Now, when this widget loads, I want to grab the sys_id of the calling catalog item because in the Server Script, I want to query the item_option_new table to get the sys_id's of all the variables:

 

find_real_file.png

 

 

When the widget initially loads, it runs the Server Script and that's where I can't seem to get the sys_id of the calling catalog item... the same issue you're having.

 

The only way that I've found do what you're trying to do is by doing this:

 

find_real_file.png

find_real_file.png

find_real_file.png

 

However, this is not the way I want to go about it.  I need to grab that sys_id before any of the HTML Template code gets rendered.

 

I forked this into my own question in the Developer Community here (my Developer Community post)

View solution in original post

18 REPLIES 18

Hi Ujjawal,



Thanks for the revert.



Actually, I want to fetch some options for the widget. Now, using GlideAggregate it will work on client controller. However, as the flow of the Widget (as I understand) is


Server --> Client Controller --> HTML


I'd like to do all the querying at the initial part itself. That's why want to know if I can access the variable's sys_id at server side.



-Mandar


Can you please share your code all three parts.


Hi Mandar,



Maybe this picture can help you. It details how to pass data between parts of a widget.


find_real_file.png


The body/HTML is linked to the controller/client - you don't have to use the data object to communicate between them.


So if you want to get info to the server script, you can do a c.server.update() in the client script, to send over the info.



BR /Miriam


Hey Miriam,



Thanks for the reply. It is a very good way to visualize different objects.



My question is regarding the server side object for 'page.field'. I don't want to send it back from client to server, was looking for a way to fetch the page.field details at server side itself.



-Mandar


Hi Mandar,



You can use c.server.update to send the data to server as mentioned below.



function() {  


      var c = this;


  c.data.abc='Any Name';


      c.update = function() {


              c.server.update().then(function (response) {


  c.data = {};


  })


      }


}



Server side you can use


if(input)


{


gs.log(input.abc);


}


else


{


//Code for intial load


}



Hope this helps.



Regards


Ujjawal